Cartesian product of ranges?

Philippe Sigaud philippe.sigaud at gmail.com
Wed Dec 14 13:10:48 PST 2011


On Wed, Dec 14, 2011 at 21:14, Justin Whear <justin at economicmodeling.com> wrote:
> I've looked through std.algorithm and std.range, but haven't found anything
> to compute the Cartesian product of several ranges. I have the nagging
> feeling that this can be accomplished by combining several of the range
> transformations in the standard library.
>
> What I'm after is something like this:
>
> alias Tuple!(int, string) P;
> assert(equal(
>        cartesianProduct([1, 2], ["a", "b"]),
>        [ P(1, "a"), P(1, "b"), P(2, "a"), P(2, "b") ]
> ));

I needed something like that a year or so ago. You can find it under
the name 'combinations' :

http://svn.dsource.org/projects/dranges/trunk/dranges/docs/algorithm.html


Philippe


More information about the Digitalmars-d-learn mailing list