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

680. move_iterator operator-> return

Section: 24.5.4.2 [move.iterator] Status: CD1 Submitter: Howard Hinnant Opened: 2007-06-11 Last modified: 2016-01-28

Priority: Not Prioritized

View other active issues in [move.iterator].

View all other issues in [move.iterator].

View all issues with CD1 status.

Discussion:

move_iterator's operator-> return type pointer does not consistently match the type which is returned in the description in [move.iter.op.ref].

template <class Iterator>
class move_iterator {
public:
    ...
    typedef typename iterator_traits<Iterator>::pointer pointer;
    ...
    pointer operator->() const {return current;}
    ...
private: 
    Iterator current; // exposition only
};

There are two possible fixes.

  1. pointer operator->() const {return &*current;}
  2. typedef Iterator pointer;

The first solution is the one chosen by reverse_iterator. A potential disadvantage of this is it may not work well with iterators which return a proxy on dereference and that proxy has overloaded operator&(). Proxy references often need to overloaad operator&() to return a proxy pointer. That proxy pointer may or may not be the same type as the iterator's pointer type.

By simply returning the Iterator and taking advantage of the fact that the language forwards calls to operator-> automatically until it finds a non-class type, the second solution avoids the issue of an overloaded operator&() entirely.

Proposed resolution:

Change the synopsis in 24.5.4.2 [move.iterator]:

typedef typename iterator_traits<Iterator>::pointer pointer;