[fusion - I think!] Multiple nested range traversal.

I recently asked a question on here about traversal of multiple indices, which produced a luke-warm reaction, mainly because I wasn't really asking the right question! So here's another try. Consider a bit of code like this for ( unsigned i=0; i!=3; ++i ) for ( unsigned j=2; j!=5;++j ) for ( unsigned k=4;k!=10;++k ) f( i, j, k ); I'd guess this comes up pretty often, and by generalising it to * an arbitrary number of ranges, of arbitrary types * f() implemented as a lambda or bind function would have quite wide applicability. I've considered writing an implemetation, which has dragged me into examining fusion and mpl in some detail, but doing so does not seem to me be trivial at all. Is there already something in Boost which does this? Thanks, Rob.

AMDG Robert Jones wrote:
I recently asked a question on here about traversal of multiple indices, which produced a luke-warm reaction, mainly because I wasn't really asking the right question!
So here's another try. Consider a bit of code like this
for ( unsigned i=0; i!=3; ++i ) for ( unsigned j=2; j!=5;++j ) for ( unsigned k=4;k!=10;++k ) f( i, j, k );
I'd guess this comes up pretty often, and by generalising it to
* an arbitrary number of ranges, of arbitrary types * f() implemented as a lambda or bind function
would have quite wide applicability.
I've considered writing an implemetation, which has dragged me into examining fusion and mpl in some detail, but doing so does not seem to me be trivial at all.
Is there already something in Boost which does this?
I don't think so. Something like this would work: make_product_range( make_counting_range(0, 3), make_counting_range(2, 5), make_counting_range(4, 10) ) should return a range whose elements are (0, 2, 4), (0, 2, 5), etc. Then as I recall, fusion has function object adapters for splitting these up into separate arguments to a function. I've attached a solution that handles the two argument case. In Christ, Steven Watanabe

On Mon, Jan 12, 2009 at 6:02 PM, Steven Watanabe
Something like this would work:
make_product_range( make_counting_range(0, 3), make_counting_range(2, 5), make_counting_range(4, 10) )
should return a range whose elements are (0, 2, 4), (0, 2, 5), etc.
Then as I recall, fusion has function object adapters for splitting these up into separate arguments to a function.
I've attached a solution that handles the two argument case.
Thanks for that Steven, that's definitely heading in the right direction. It's taking me a while to digest, but doing so is proving highly informative and useful. Rob.
participants (2)
-
Robert Jones
-
Steven Watanabe