[Boost-bugs] [Boost C++ Libraries] #10894: Add an adaptor to iterate a range in pairs of (current element, next element)

Subject: [Boost-bugs] [Boost C++ Libraries] #10894: Add an adaptor to iterate a range in pairs of (current element, next element)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-12-23 12:07:00


#10894: Add an adaptor to iterate a range in pairs of (current element, next
element)
-------------------------------------------------+-------------------------
 Reporter: Matthäus Brandl (brandl.matthaeus@… | Owner: neilgroves
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: range
  Version: Boost Development Trunk | Severity: Not
 Keywords: range adaptor pairwise | Applicable
-------------------------------------------------+-------------------------
 An often needed functionality is iterating a range and accessing the
 current and next element of the range.

 Currently this can be done as follows:
 {{{#!C++
 assert(someVec.size > 1);
 for(auto const & pair, boost::make_iterator_range(
     boost::make_zip_iterator(
         boost::make_tuple(
             someVec.cbegin(), std::next(someVec.cbegin()))),
     boost::make_zip_iterator(
         boost::make_tuple(
             std::prev(someVec.cend()), someVec.cend())))
         )
 {
     auto current = boost::get<0>(pair);
     auto next = boost::get<1>(pair);
 }
 }}}

 An adaptor would strongly increase readability:
 {{{#!C++
 assert(someVec.size > 1);
 using boost::adaptors::operator|;
 for(auto const & pair, someVec | boost::adaptors::paired())
 {
     pair.current();
     pair.next();
 }
 }}}

 Of course the difference between current and next could be made
 customizable as well.

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