Boost logo

Boost Users :

Subject: Re: [Boost-users] Iterators for the cartesian product
From: Larry Evans (cppljevans_at_[hidden])
Date: 2011-06-13 18:54:12


On 06/13/11 15:25, Larry Evans wrote:
> On 06/13/11 15:06, kelvSYC wrote:
>>
>> On Jun 13, 2011, at 8:19 AM, Larry Evans wrote:
[snip]
>> So I'd want z to be equal to
>>
>> std::vector<std::vector<int>>({{1,4}, {1,5}, {2,4}, {2,5}, {3,4}, {3,5}});
>>
>> Is there something in boost that will give me this sequence (or at least iterators therein?)
>
> I pretty sure there is none since the thread I mentioned previously did
> not mention one and people replying to that thread indicated it would
> be desirable.

The attached code, using boost multi_array, produces output shown in
2nd attachment. It does use some utility functions for printing out
the mult_array, but I'm sure you could roll-your-own without much
problem. The interesting thing is that it will work for not
just vectors, but any dimension multi_array; however, I think
it depends on the multi_array's being in c_storage_order.
I tried inner_product with the code from the Budd book; however,
that failed to get the right answer for fortran_storage order.

The last result output is simply a flattened version of the immediately
preceding result output. I think that last output is closer to the
std::vector<std::vector<int> > form you showed previously.

HTH.

-Larry





Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net