Are there any cases in which it does make sense to use const&&
in range-for loops?
for (const auto && x : c) // ?
Are there any cases in which it does make sense to use const&&
in range-for loops?
for (const auto && x : c) // ?
Short answer: no, there are no uses for const auto&&
in range-for loops
(or otherwise)
You would use rvalue references
if you wish to move objects in an optimized manner. You can't do that (in general) unless you can modify the object moved from. So const rvalues
(*) are of no practical use (you can't move from them because you can't modify them).
range-for loops
don't bring anything to the table in this discussion about const auto&&
.
Check for instance this SO post: Do rvalue references to const have any use?
The only found use of const rvalue reference is to delete some function overloads. This doesn't apply to range-for loops
.
(*) by the way, const auto&&
is a const rvalue reference, not a forwarding reference.