[Boost-bugs] [Boost C++ Libraries] #8617: Surprising/wrong semantics of counting_range

Subject: [Boost-bugs] [Boost C++ Libraries] #8617: Surprising/wrong semantics of counting_range
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-05-27 14:20:23


#8617: Surprising/wrong semantics of counting_range
-------------------------------+--------------------------------------------
 Reporter: pbazant@… | Owner: neilgroves
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: range
  Version: Boost 1.53.0 | Severity: Problem
 Keywords: range |
-------------------------------+--------------------------------------------
 I would expect

 counting_range(begin(rng),end(rng));

 to be equivalent to

 counting_range(rng);

 which does not seem to be the case. The code in the library looks like it
 constructs the range from the first and last _value_ of the rng:

    template<class Range>
     inline iterator_range<counting_iterator<BOOST_DEDUCED_TYPENAME
 range_value<Range>::type> >
     counting_range(Range& rng)
     {
         typedef counting_iterator<BOOST_DEDUCED_TYPENAME
 range_value<Range>::type> counting_iterator_t;
         typedef iterator_range<counting_iterator_t> result_t;
         return boost::empty(rng)
             ? result_t()
             : result_t(
                 counting_iterator_t(*boost::begin(rng)),
                 counting_iterator_t(*boost::prior(boost::end(rng))));
     }

 I want to be able to use the counting range in a range based for like
 this:

 for(auto it : counting_range(rng | indexed(0)))
 {
 *it;
 it.index();
 }
 I also vote for a way to use indexed adaptor in the range based for loop
 directly. The model for the new indexed adaptor could be something like
 enumerate() in Python. Much much nicer than using a counter variable.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8617>
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:13 UTC