Created on 2013-11-11.00:00:00 last changed 131 months ago
Proposed resolution:
This wording is relative to N3797.
Edit [reverse.iterator], class template reverse_iterator synopsis, as indicated:
namespace std { template <class Iterator> class reverse_iterator : public iterator<typename iterator_traits<Iterator>::iterator_category, typename iterator_traits<Iterator>::value_type, typename iterator_traits<Iterator>::difference_type, typename iterator_traits<Iterator>::pointer, typename iterator_traits<Iterator>::reference> { public: […]unspecifiedreference operator[](difference_type n) const; […] }; […] }
Edit [reverse.iter.opindex] as indicated:
unspecifiedreference operator[]( typename reverse_iterator<Iterator>::difference_type n) const;-1- Returns:
current[-n-1]*(current + n).
[ 2014-02-13 Issaquah : close as NAD ]
Currently reverse_iterator::operator[]() returns "current[-n-1]" and has an "unspecified" return type.
When Iterator is a mutable random access iterator, the expression "current[-n-1]" calls "Iterator::operator[] const", which returns a const reference. This const reference cannot be converted back to a mutable reference. This issue is related to the "unspecified" return value of reverse_iterator::operator[], see defect 386. The -1 is due to "current" pointing one item beyond the reverse_iterator's real current value. The current libstdc++ implementation reads "*(current + n)" for reverse_iterator::operator[]. This copied current, advances (backwards) via operator+ and dereferences. It bypasses the issues due to reverse_iterator::operator[] being const by copying the iterator.History | |||
---|---|---|---|
Date | User | Action | Args |
2014-02-14 07:07:05 | admin | set | messages: + msg6858 |
2014-02-14 07:07:05 | admin | set | status: new -> nad |
2014-01-12 14:27:30 | admin | set | messages: + msg6781 |
2013-11-11 00:00:00 | admin | create |