Iterating over a variant conaining an associative array
Juanjo Álvarez" <juanjux at gmail.com>
Juanjo Álvarez" <juanjux at gmail.com>
Thu Aug 23 07:57:23 PDT 2012
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 at 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?
More information about the Digitalmars-d-learn
mailing list