Thread overview |
---|
November 11, 2015 Multiple range enumeration | ||||
---|---|---|---|---|
| ||||
Hi, If I have multiple ranges, say: auto a = [1, 2, 3]; auto b = ["a", "b", "c"]; auto c = ["x", "y", "z"]; I'd like a composition range that enumerate all combinations of these ranges, having the same effect as a nested foreach loop: foreach (i; a) { foreach (j; b) { foreach (k; c) { writlen(i, j, k); } } } Is there such a generic function in std lib? |
November 11, 2015 Re: Multiple range enumeration | ||||
---|---|---|---|---|
| ||||
Posted in reply to puming | On Wednesday, 11 November 2015 at 02:38:19 UTC, puming wrote: > Hi, > > If I have multiple ranges, say: > > auto a = [1, 2, 3]; > auto b = ["a", "b", "c"]; > auto c = ["x", "y", "z"]; > > I'd like a composition range that enumerate all combinations of these ranges, > having the same effect as a nested foreach loop: > > foreach (i; a) { > foreach (j; b) { > foreach (k; c) { > writlen(i, j, k); > } > } > } > > Is there such a generic function in std lib? http://dlang.org/phobos/std_algorithm_setops.html#.cartesianProduct ? |
November 11, 2015 Re: Multiple range enumeration | ||||
---|---|---|---|---|
| ||||
Posted in reply to cym13 | On Wednesday, 11 November 2015 at 02:55:25 UTC, cym13 wrote:
> On Wednesday, 11 November 2015 at 02:38:19 UTC, puming wrote:
>> Hi,
>>
>> If I have multiple ranges, say:
>>
>> auto a = [1, 2, 3];
>> auto b = ["a", "b", "c"];
>> auto c = ["x", "y", "z"];
>>
>> I'd like a composition range that enumerate all combinations of these ranges,
>> having the same effect as a nested foreach loop:
>>
>> foreach (i; a) {
>> foreach (j; b) {
>> foreach (k; c) {
>> writlen(i, j, k);
>> }
>> }
>> }
>>
>> Is there such a generic function in std lib?
>
> http://dlang.org/phobos/std_algorithm_setops.html#.cartesianProduct ?
Thanks :-)
|
Copyright © 1999-2021 by the D Language Foundation