Рет қаралды 304
This presentation focuses on what happens when non-trivial objects are passed to functions by value. Often this necessitates calling the copy or move constructor of the object's type. This call can be elided when the argument is a prvalue, such as when it is the result of another function or a temporary object of the expected type. The constructor can be elided even if the target function happens to be virtual.
But this doesn't work when invoking a std::function, std::move_only_function, std::function_ref, or even std::reference_wrapper. When the target of these abstractions takes objects by value, there will be at least one additional copy/move of the arguments even if they are prvalues.
But what if this were not the case?
This presentation will explain why library-level abstractions incur the overhead of an additional copy/move, and present a technique for avoiding this overhead.