Presentation is loading. Please wait.

Presentation is loading. Please wait.

C++ TALK The short version! :D. OVERVIEW You’ll hopefully know the basics, so this talk covers: ► C++ templates ► C++11 cool things.

Similar presentations


Presentation on theme: "C++ TALK The short version! :D. OVERVIEW You’ll hopefully know the basics, so this talk covers: ► C++ templates ► C++11 cool things."— Presentation transcript:

1 C++ TALK The short version! :D

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

3 C++ TEMPLATES ► Conceptually similar to Java generics ► More powerful though

4 C++ TEMPLATE EXAMPLES

5

6

7 C++ TEMPLATE THOUGHTS ► Generated granularly on-demand ► “Granularly” explained in a minnit. ► Can be inlined ► Fast at runtime

8 This part intentionally left blank.

9 C++11 COOL THINGS ► 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)

10 STATIC_ASSERT

11 STATIC_ASSERT CONTINUED

12 FIRST OFF, LAMBDAS!

13 LAMBDAS – CAPTURE GROUP (‘i’ is read-only in this context. So we can’t do ++i)

14 LAMBDAS – ARGUMENT/RETURN

15 THREADING

16 THREADING – NATIVE_HANDLE()

17 THREADING – ATOMIC DATA TYPES ► Under ► Everything from atomic_float to atomic_uint_fast32_t

18 RRID STUFFS ► Std::shared_ptr ► Std::unique_ptr ► Std::weak_ptr ► …

19 STD::SHARED_PTR

20 STD::UNIQUE_PTR

21 STD::WEAK_PTR

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

23 STD::ARRAY

24 STD::VECTOR

25 MOVE SEMANTICS ► 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.

26 WHAT ARE MOVE SEMANTICS? ► 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

27 WHY DO WE CARE? ► 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.

28 WHY DO WE CARE? ► This code used to be bad: ► It would call string::string(const string&) 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

29 SUMMARY ► 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


Download ppt "C++ TALK The short version! :D. OVERVIEW You’ll hopefully know the basics, so this talk covers: ► C++ templates ► C++11 cool things."

Similar presentations


Ads by Google