On Wed, Feb 10, 2010 at 22:28, GG <g@g.com> wrote:
I try to use variant as associative array with dmd2.039,
I got core.exception.RangeError@main(28): Range violation
I had the same problem a few months ago. It's the same with Algebraic, too bad.
alias TypeTuple!(int, string, double, char) Universe;
alias Algebraic!Universe Var;
Var[string] test;
test["abc"] = 3; // fails, also with range violation.
test["abc"] = Var(3); // the same. even wrapped in an Algebraic/Variant call, you cannot initialize it.
test = ["abc":3]; // Error: cannot implicitly convert expression (["abc":1]) of type int[string] to VariantN!(maxSize,int,string,double,char)[string]
test = ["abc":Var(3)]; // Error: cannot implicitly convert expression
(["abc":opCall(3)]) of type VariantN!(maxSize)[string] to...
(note the weird expression, but with a correct type.)
In the end, I had to use a two-level hack:
Variant[] vars;
int[char[]][int] indices;
vars ~= "Jan";
indices[0]["Month"] = vars.length-1;
or something like this. Sad, but true...
Philippe