Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > reverse iterators revisited

Thread Tools

reverse iterators revisited

Alexander Stippler
Posts: n/a

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>
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,

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
plain iterators and reverse iterators on vector, India C++ 10 08-08-2009 08:28 AM
reverse iterators and erasing Christopher C++ 1 02-26-2009 04:19 AM
NVIDIA Forceware Revisited article Silverstrand Front Page News 0 09-22-2005 01:37 PM
Iterators and reverse iterators Marcin Kaliciński C++ 1 05-08-2005 09:58 AM
Stacks Queues Reverse Reverse Polish dogbite C++ 4 10-10-2003 05:06 AM