Opened 8 years ago
Last modified 7 years ago
#10894 new Feature Requests
Add an adaptor to iterate a range in pairs of (current element, next element)
Reported by: | Owned by: | Neil Groves | |
---|---|---|---|
Milestone: | To Be Determined | Component: | range |
Version: | Boost Development Trunk | Severity: | Not Applicable |
Keywords: | range adaptor pairwise | Cc: |
Description
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:
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:
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.
Note:
See TracTickets
for help on using tickets.
This can also be achieved in a more concise way: