
What do you mean by "handles"? Do you want to just package up the for_each function together with the sequence type you want to operate on, effectively reducing everything to a unary function accepting the op parameter? I don't know of such an abstraction in boost.
Yes, exactly. This looks like a quite general concept for me and I was wondering if something has already been implemented. Maybe a small example is: struct std_algorithm { template< Op > static void for_each( std::vector< double > &vec , Op op ) { std::for_each( vec.begin() , vec.end() , op ); } }; struct thrust_algorithm { template< Op > static void for_each( thrust::device_vector< double > &vec , Op op ) { thrust::for_each( vec.begin() , vec.end() , op ); } }; // the complex algorithm we want to implement template< class Algorithm , class Sequence > void do_something( Sequence &seq ) { ... Algebra::for_each( seq , op() ); ... } // use youe code via // the standard version std::vector< double > vec1; do_something< std_algorithm >( vec1 ); // the thrust (CUDA) version thrust::device_vector< double > vec2; do_something< thrust_algorithm >( vec2 );
There was a topic that was brought up by...I'm going to say Joel Falcou, but I may have that wrong...discussing segmented iterators and iteration in general (I would search "segmented iterators"). I believe his use case was enabling the use of simd instruction in the iteration, which required special treatment of the first few and last few elements of the range. One abstraction that makes this efficient is to push the iteration to the responsibility of the range or sequence you're operating on. This seems to be roughly what you might want to consider doing here (and is basically equivalent to packaging the for_each function up with the sequence, as I suggested above).
I think you mean this one http://thread.gmane.org/gmane.comp.lib.boost.devel/209431 altough I am not sure I fully understand. Karsten