
10.02.2013 17:10, Ian Hobson:
Is there any interest in a version of for_each that operates on each adjacent pair of elements in a range? [...] Initial implementation available at http://github.com/irh/adjacent_for_each
I have implemented for_each_adjacent on project I worked on (sorry, can't share source). I had two versions: for InputIterator and ForwardIterator. Selection was implemented as tag dispatching of iterator_category. You need special version for InputIterator which maintains temporary copy of value_type, due to 24.1.1/3: [Note: For input iterators, a == b does not imply ++a == ++b. (Equality does not guarantee the substitution property or referential transparency.) Algorithms on input iterators should never attempt to pass through the same iterator twice. They should be single pass algorithms.] In this regard your version at https://github.com/irh/adjacent_for_each/blob/master/boost/algorithm/adjacen... is broken. Because it advertises to work on InputIterator, but it dereferences iterator at same position several times. As the result current implementation is for ForwardIterator. P.S. Consider implementation of companion - transform_adjacent. Maybe even consider version which accepts "count of adjacent elements within each iteration" as template non-type parameter. Or maybe choose some another approach involving Boost.Range? -- Evgeny Panasyuk