Title
move_iterator operator-> return
Status
cd1
Section
[move.iterator]
Submitter
Howard Hinnant

Created on 2007-06-11.00:00:00 last changed 172 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Change the synopsis in [move.iterator]:

typedef typename iterator_traits<Iterator>::pointer pointer;
Date: 2015-09-21.13:37:08

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.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg3423
2007-06-11 00:00:00admincreate