We will analyse such code
template
typename std::remove_reference::type&& move(T&& obj) noexcept {
using ReturnType = std::remove_reference::type&&;
return static_cast(obj);
}
class Object;
void f(const Object&) { std::cout << "const Object&\n"; }
void f(Object&) { std::cout << "Object&\n"; }
void f(Object&&) { std::cout << "Object&&\n"; }
template
void use(T&& g) {
f(std::forward(g)); // forwards original type to f()
}
Your abilities after Move semantics in C++ training
- you know when move operations are applied
- you can implement move operations in classes
-
you know when
std::move()
is necessary and when it is not - you can avoid interface bloat with forwarding references
- you know and use perfect forwarding for code optimization
Agenda
- r-values and l-values
- move constructor and move assignment operator
- implementation of move semantics
- rule of 0, 3, 5
-
std::move()
and it's implementation - forwarding reference
- reference collapsing
-
std::forward()
and perfect forwarding - copy elision and RVO (Return Value Optimization)
Activities
- pre-work to be done before our training
- pre-test pre-test at the beginning
- exercises followed by trainers implementation
- coding dojo
- participants solutions code review
- post-work with code review
- post-test one week after the training
- certificate of completion
Duration
- 1 day (7 hours with breaks)
Form
- online
- classroom
Order Move semantics in C++ training
Related trainings
Modern C++
Move semantics is a key feature of C++11.
Declarations of
Declarations of
= default;
and = delete;
are discussed deeply in this training. Templates
Knowledge of templates can help to understand what type is exactly deduced in template parameters and how perfect forwarding can be combined with variadic templates