When to use decltype(auto)?
Show answer and explanation
Use decltype(auto) when a deduced declaration or return type must preserve exactly what decltype(expression) yields, including references. It is powerful for forwarding accessors but can accidentally return a dangling reference.
Use decltype(auto) when a deduced declaration or return type must preserve exactly what decltype(expression) yields, including references. It is powerful for forwarding accessors but can accidentally return a dangling reference.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.