This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++11 status.

872. move_iterator::operator[] has wrong return type

Section: [move.iter.op.index] Status: C++11 Submitter: Doug Gregor Opened: 2008-08-21 Last modified: 2017-02-03

Priority: Not Prioritized

View all issues with C++11 status.


move_iterator's operator[] is declared as:

reference operator[](difference_type n) const;

This has the same problem that reverse_iterator's operator[] used to have: if the underlying iterator's operator[] returns a proxy, the implicit conversion to value_type&& could end up referencing a temporary that has already been destroyed. This is essentially the same issue that we dealt with for reverse_iterator in DR 386.

[ 2009-07-28 Reopened by Alisdair. No longer solved by concepts. ]

[ 2009-08-15 Howard adds: ]

I recommend closing this as a duplicate of 1051 which addresses this issue for both move_iterator and reverse_iterator.

[ 2009-10 Santa Cruz: ]

Move to Ready. Note that if 1051 is reopened, it may yield a better resolution, but 1051 is currently marked NAD.

Proposed resolution:

In [move.iterator] and [move.iter.op.index], change the declaration of move_iterator's operator[] to:

reference unspecified operator[](difference_type n) const;


[ San Francisco: ]

NAD Editorial, see N2777.