Difference between revisions of "Intermediate C++ Game Programming Tutorial 20"
(Created page with "In this video we learn about r-value reference and move semantics, which is perhaps the most important feature that was added in the C++11 update. This is going to allow us to...") |
|||
Line 11: | Line 11: | ||
== Video Timestamp Index == | == Video Timestamp Index == | ||
* [https://youtu.be/93mlQnWbyuk Tutorial 20] | * [https://youtu.be/93mlQnWbyuk Tutorial 20] | ||
+ | |||
+ | == Note == | ||
+ | If you are using Visual Studio 2017, you might notice that our move members are not being used during <code>std::vector</code> growth even after we have 'properly' implemented them. This is expected, so don't pay it much mind at the moment. | ||
+ | |||
+ | The reason for this is that <code>std::vector</code> will only use the move members if they are guaranteed not to throw any exceptions (as per the standard). This issue will be dealt with in Intermediate 22 (tutorial on exceptions). For your interest, you can enable the move optimization by declaring your move ctor as <code>Surface( Surface&& ) noexcept</code>. The same should be done for the move assignment and the destructor. | ||
+ | |||
+ | You might wonder why Chili had no problems in the video. In the video, Chili was using Visual Studio 2015, which does not conform to the standard in this point, so it uses the move members regardless of whether or not they are marked noexcept; | ||
== Source Code == | == Source Code == |
Revision as of 20:10, 8 January 2018
In this video we learn about r-value reference and move semantics, which is perhaps the most important feature that was added in the C++11 update. This is going to allow us to manage and transfer our resources in a precise and efficient manner. It is sexy as fuck and I love it.
Topics Covered
- r-values and l-values
- r-value reference function overloading
- Move constructor and move assigment
- Rule of 5
-
std::move
-
std::make_move_iterator
Video Timestamp Index
Note
If you are using Visual Studio 2017, you might notice that our move members are not being used during std::vector
growth even after we have 'properly' implemented them. This is expected, so don't pay it much mind at the moment.
The reason for this is that std::vector
will only use the move members if they are guaranteed not to throw any exceptions (as per the standard). This issue will be dealt with in Intermediate 22 (tutorial on exceptions). For your interest, you can enable the move optimization by declaring your move ctor as Surface( Surface&& ) noexcept
. The same should be done for the move assignment and the destructor.
You might wonder why Chili had no problems in the video. In the video, Chili was using Visual Studio 2015, which does not conform to the standard in this point, so it uses the move members regardless of whether or not they are marked noexcept;