Forwarding reference

auto&& is called a forwarding reference (also referred to as a universal reference). It can bind to anything which makes it useful for certain cases. Forwarding references will, just like const references, extend the lifetime of a temporary. But in contrast to the const reference, auto&& allows you to mutate objects it references, temporaries included.

Use auto&& for variables that you only forward to some other code. In those forwarding cases you rarely care about whether the variable is a const or a mutable, you just want to pass it to some code that actually going to use the variable.

It's important to note that only auto&& and T&& in a template method are forwarding references. Using the && syntax with an explicit ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.