Cartesian product of ranges?

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

On Wed, Dec 14, 2011 at 21:14, Justin Whear <justin at> 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' :


More information about the Digitalmars-d-learn mailing list