reverse iterators revisited

Discussion in 'C++' started by Alexander Stippler, Jan 1, 2004.

  1. 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
    Alexander Stippler, Jan 1, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Boban Dragojlovic

    Dynamic Buttons and Event Handlers, revisited

    Boban Dragojlovic, Jun 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,862
    Boban Dragojlovic
    Jun 24, 2003
  2. dogbite
    Replies:
    4
    Views:
    678
    osmium
    Oct 10, 2003
  3. Marcin Kaliciñski

    Iterators and reverse iterators

    Marcin Kaliciñski, May 8, 2005, in forum: C++
    Replies:
    1
    Views:
    475
    Kai-Uwe Bux
    May 8, 2005
  4. Christopher

    reverse iterators and erasing

    Christopher, Feb 25, 2009, in forum: C++
    Replies:
    1
    Views:
    312
    Christopher
    Feb 26, 2009
  5. , India
    Replies:
    10
    Views:
    1,057
    James Kanze
    Aug 8, 2009
Loading...

Share This Page