1 / 29

C++ Talk

C++ Talk. The short version! :D. You’ll hopefully know the basics, so this talk covers: C++ templates C++11 cool things. Overview. Conceptually similar to Java generics More powerful though. C++ Templates. C++ Template Examples. C++ Template Examples. C++ Template Examples.

kylee
Télécharger la présentation

C++ Talk

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C++ Talk The short version! :D

  2. You’ll hopefully know the basics, so this talk covers: • C++ templates • C++11 cool things Overview

  3. Conceptually similar to Java generics • More powerful though C++ Templates

  4. C++ Template Examples

  5. C++ Template Examples

  6. C++ Template Examples

  7. Generated granularly on-demand • “Granularly” explained in a minnit. • Can be inlined • Fast at runtime C++ Template Thoughts

  8. This part intentionally left blank.

  9. Static_assert • STL threading (with a new memory model!) • ALL THE RRID • Lambdas • Why you shouldn’t use normal arrays • Move semantics (the important part) C++11 Cool THings

  10. Static_assert

  11. Static_Assert continued

  12. First off, Lambdas!

  13. (‘i’ is read-only in this context. So we can’t do ++i) Lambdas – Capture Group

  14. Lambdas – Argument/Return

  15. Threading

  16. Threading – native_handle()

  17. Under <atomic> • Everything from atomic_float to atomic_uint_fast32_t Threading – Atomic Data TYpes

  18. Std::shared_ptr<T> • Std::unique_ptr<T> • Std::weak_ptr<T> • … RRID Stuffs

  19. Std::shared_ptr

  20. Std::unique_ptr

  21. Std::weak_ptr

  22. (std::vector | std::array) > raw arrays • Checked STL • [] guarantees 0 bounds checking with unchecked STL • Iterator support • Support for .size()/.max_size() Std::vector/std::array

  23. std::array

  24. Std::vector

  25. Allow for no-fail moving from one variable to another • Really low overhead • Can be used in place of copying somewhat often • I like to move it, move it. Move semantics

  26. Denoted by && ‘double-ref/ref-ref’ • Basically: • One variable, A, kills another, b. • A steals b’s innards • A places b’s innards in itself What are move semantics?

  27. Example of strings using copy vs move constructors: • By doing copy = primary, invoke string copy constructor • Allocate new char[] • Copy from primary to copy… • By doing move = primary, invoke string move constructor • Steal char[] pointer from primary • “Primary” is no longer useable after this. Why do we care?

  28. This code used to be bad: • It would call string::string(conststring&) once or twice • Now it calls string::string(string&&) once or twice • Now just a maximum of six assignments • As opposed to 2 allocs, 6 assignments, 2 memcpys Why do we care?

  29. Std::thread provides for easy threading • Templates are extremely flexible • Also generated on demand • Lambdas are great for one-off functions • Use std::unique_ptr and std::shared_ptr in place of raw pointers • Use std::array/std::vector instead of raw arrays Summary

More Related