August 23, 2012 Iterating over a variant conaining an associative array | ||||
---|---|---|---|---|
| ||||
This works: string[] l = ["one", "two", "three"]; auto vl = Variant(vl); foreach(Variant i; vlist) writeln(i); (Note how I don't need the contained type for iterating over it). This doesn't work: string[int] d = [1: "one", 2: "two", 3: "three)]; auto vd = Variant(d); foreach(Variant i; vd) writeln(i); This gives the error: std.variant.VariantException@std\variant.d(1209): Variant: attempting to use incompatible types uint and immutable(char)[] Getting the elements with the opIndex (like vd[1]) works. Is there any other way to iterate over vd elements without knowing the exact type and retrieving it with get!TYPE? |
Copyright © 1999-2021 by the D Language Foundation