Re: [Boost-bugs] [Boost C++ Libraries] #2539: advance() and distance() for new iterator concepts

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2539: advance() and distance() for new iterator concepts
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-12-30 14:53:34


#2539: advance() and distance() for new iterator concepts
------------------------------------+---------------------------------------
 Reporter: debionne@… | Owner: dave
     Type: Bugs | Status: new
Milestone: Boost 1.38.0 | Component: iterator
  Version: Boost 1.37.0 | Severity: Problem
 Keywords: |
------------------------------------+---------------------------------------

Comment(by paul):

 Any update on this? I would like to add that this is not simply a
 effeciency issue, it leads to erroneous behavior if a boost iterator is
 used with std::advance and if nothing else there should be a strong
 warning in the documentation, i.e. the following test fails
 std::advance(some_boost_iterator.end(), -1) != some_boost_iterator.end().

 Simple test,
 {{{
 #!cpp
 int main()
 {
         test_iter itr(0);

         itr++;
         assert(*itr == 1);

         ++itr;
         assert(*itr == 2);

         itr+=8;
         assert(*itr == 10);

         itr-=8;
         assert(*itr == 2);

         --itr;
         assert(*itr == 1);

         itr--;
         assert(*itr == 0);

         std::advance(itr, 5); // passes, but less efficient than expected
         assert(*itr == 5);

         std::advance(itr, -5); // iterator is not moved
         assert(*itr == 0); // FAILURE, *itr == 5
 }



 struct test_iter
   : public boost::iterator_facade<
         test_iter
       , int
       , boost::random_access_traversal_tag,
           int
>
 {

  public:
     test_iter() : m_value(0) {}
     explicit test_iter(int v) : m_value(v) {}

     test_iter(test_iter const& other) : m_value(other.m_value) {}

     bool equal(test_iter const& other) const
     {
         return this->m_value == other.m_value;
     }

     void increment() { ++m_value; }
     void decrement() { --m_value; }

     int dereference() const {
                 return m_value;
         }

         void advance(difference_type offset)
         {
                 m_value+=offset;
         }

         difference_type distance_to(const test_iter& rhs)
         {
                 return m_value-rhs.m_value;
         }

         int m_value;
 };


 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/2539#comment:2>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC