reverse iterators revisited

  • Thread starter Alexander Stippler
  • Start date
A

Alexander Stippler

Hello,

is it reasonable, that most stl-implementations allow conversion from
iterator to const_iterator via conversion constructors like the following?

template<class _Other>
reverse_iterator(const reverse_iterator<_Other>& _Right);

This signature unfortunately allows the other direction, wich is
semantically surely not the desired thing. GCC for example uses this way
not only for reverse_iterators.
I wrote equality comparison operators for reseverse iterators nad
const_reverse_iterators (see thread "reverse iterator operator==") and here
the trouble starts. Greenly, as I sometimes act, I wrote twice operator==()
(and twice operator!=):

template <typename Iter> // typename Const<Iter>::type is the const version
bool // of iterator type Iter. Some little magic :).
operator==(const std::reverse_iterator<typename Const<Iter>::type> &lhs,
const std::reverse_iterator<Iter> &lhs);

template <typename Iter>
bool
operator==(const std::reverse_iterator<Iter> &lhs,
const std::reverse_iterator<typename Const<Iter>::type> &lhs);

and of course this yields ambiguity !!!

Tell me, what do you think of these STL reverse_iterator implementation. IMO
thei are doing it the easy way, allowing any reverse_iterator to be
converted to any other reverse_iterator. Even more, some allow this for
normal iterators, too. Doesn't this provoke trouble,

regards,
alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top