Boost logo

Boost :

Subject: Re: [boost] [algorithm] adjacent_for_each interest?
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2013-02-12 08:24:36


On 10-02-2013 14:10, Ian Hobson wrote:
> Hi,
>
> Is there any interest in a version of for_each that operates on each adjacent pair of elements in a range?
>
> #include <iostream>
> #include <boost/algorithm/adjacent_for_each.hpp>
>
> void PrintInts(int a, int b) {
> std::cout << '(' << a << ", " << b << ")\n";
> }
>
> int main() {
> const int ints[] = {0, 1, 2, 3, 4};
> boost::algorithm::adjacent_for_each(ints, ints + 5, PrintInts);
> }

Yes, I think would be a good utillity. But consider generalizing:

   for_each_slice<N>( ..., PrintInts() )

so we can decide how big the sliding window is. Perhaps it's better with
a run-time argument:

   for_each_slice( 3, // size of slize
                   iterator begin,
                   iterator end,
                   Functor fun )

and provide range overload in terms of the iterator version.

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk