Title
reverse_iterator/move_iterator difference has invalid signatures
Status
cd1
Section
[reverse.iter.nonmember][move.iter.nonmember]
Submitter
Bo Persson

Created on 2007-06-10.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

[ Pre Bellevue: This issue needs to wait until the auto -> return language feature goes in. ]

Date: 2010-10-21.18:28:33

Proposed resolution:

Change the synopsis in [reverse.iterator]:

template <class Iterator1, class Iterator2>
  typename reverse_iterator<Iterator>::difference_type auto operator-(
    const reverse_iterator<Iterator1>& x,
    const reverse_iterator<Iterator2>& y) -> decltype(y.current - x.current);

Change [reverse.iter.opdiff]:

template <class Iterator1, class Iterator2>
  typename reverse_iterator<Iterator>::difference_type auto operator-(
    const reverse_iterator<Iterator1>& x,
    const reverse_iterator<Iterator2>& y) -> decltype(y.current - x.current);

Returns: y.current - x.current.

Change the synopsis in [move.iterator]:

template <class Iterator1, class Iterator2>
  typename move_iterator<Iterator>::difference_type auto operator-(
    const move_iterator<Iterator1>& x,
    const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());

Change [move.iter.nonmember]:

template <class Iterator1, class Iterator2>
  typename move_iterator<Iterator>::difference_type auto operator-(
    const move_iterator<Iterator1>& x,
    const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());

Returns: x.base() - y.base().

Date: 2007-06-10.00:00:00

In C++03 the difference between two reverse_iterators

ri1 - ri2

is possible to compute only if both iterators have the same base iterator. The result type is the difference_type of the base iterator.

In the current draft, the operator is defined as [reverse.iter.opdiff]

template<class Iterator1, class Iterator2>
typename reverse_iterator<Iterator>::difference_type
   operator-(const reverse_iterator<Iterator1>& x,
                    const reverse_iterator<Iterator2>& y);

The return type is the same as the C++03 one, based on the no longer present Iterator template parameter.

Besides being slightly invalid, should this operator work only when Iterator1 and Iterator2 has the same difference_type? Or should the implementation choose one of them? Which one?

The same problem now also appears in operator-() for move_iterator [move.iter.nonmember].

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