Be Careful With Braces When Returning
Explore how returning values with braces in C++17 affects move semantics, causing copies instead of moves. Understand the implications for types like std::unique_ptr, std::vector, and std::string, and learn to manage optional types effectively.
We'll cover the following...
We'll cover the following...
You might be surprised by the following code:
According to the Standard if you wrap a return value into braces {} then you prevent move operations from happening. The returned object will be copied only.
This is similar to the case with non-copyable types:
...