Can't iterate over range

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 4 06:35:37 PST 2017


On 02/04/2017 12:31 PM, Profile Anaysis wrote:
> I am trying to iterate over the combinations of a set using the code
>
> https://rosettacode.org/wiki/Power_set#D
>
> I have an array which I call powerSet on and I get a result of
> MapResult. I have tried to foreach or front/popFront and even each() on
> it but I can never get the result as the same array type that I started
> with.

To create an array from a range, you can use std.array.array:

http://dlang.org/phobos/std_array.html#.array

> What is MapResult(the algorithm that generates the result lazily?)

Yes, it's a struct that gives you one element at a time, lazily generated.

> and
> how do we easily iterate over the results like we would with an array?

foreach and empty/front/popFront should both work. If you can't get them 
to work, show what you tried.


More information about the Digitalmars-d-learn mailing list