use variant as associative array
Philippe Sigaud
philippe.sigaud at gmail.com
Thu Feb 11 11:56:25 PST 2010
On Wed, Feb 10, 2010 at 22:28, GG <g at g.com> wrote:
> I try to use variant as associative array with dmd2.039,
>
> I got core.exception.RangeError at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100211/af17c0c7/attachment.htm>
More information about the Digitalmars-d-learn
mailing list