C++ Logo


Advanced search

const && and for( : ) loop

From: Ryan P. Nicholl <rnicholl_at_[hidden]>
Date: Tue, 02 Feb 2021 23:31:27 +0000
I'd like to suggest a meaningful designation for const &&..

Consider for example, the value pointed to by a std::shared_ptr, which might be a shared state and therefore immutable, but if you have an rvalue shared_ptr, it might be temporary and therefore destroyed at the end of the current context. Thus, T const &&, a temporary value which may not be modified, might have some meaning.

Currently for ( : ) loop doesn't extend lifetime of T&&. I suggest, first, if the evaluation expression of for ( : ) results in T && type, then all temporaries in the object to be iterated upon are extended in lifetime until the end of the loop body.

This would give some meaning to T const &&, since it would designate a temporary which may not be modified. (getting const overloads to the iterator values and such) while extending the lifetime of the shared pointer throughout the life of the loop body.


Ryan P. Nicholl
Tel: (678)-358-7765
Tox: 52B3A61CDAF88BCC854F568933F071E3530600CDBA3D5354AADC9AD179575D68021AE959719D

Received on 2021-02-02 17:31:41