View mode: basic / threaded / horizontal-split · Log in · Help
February 11, 2010
Re: use variant as associative array
I tried your trick but I got "Error: cannot append type string to type VariantN!(maxSize)[]" 
on :  vars ~= "Jan";

I found this : http://d.puremagic.com/issues/show_bug.cgi?id=3692, the issue has been REOPEN.

Thanks for helping !
February 11, 2010
Re: use variant as associative array
Sorry, but I ckicked on REPLY and it created a new thread after posting!?
February 11, 2010
Re: use variant as associative array
On Thu, Feb 11, 2010 at 21:22, GG <g@g.com> wrote:

> I tried your trick but I got "Error: cannot append type string to type
> VariantN!(maxSize)[]"
> on :  vars ~= "Jan";
>
> I found this : http://d.puremagic.com/issues/show_bug.cgi?id=3692, the
> issue has been REOPEN.
>
> Thanks for helping !
>

Hmm, it worked for me, but that was almost a year ago. Maybe I wrapped a
Variant around?

vars ~= Variant("Jan");

(*testing*)

Yes, it works:

Variant[] vars;
int[char[]][int] indices;

vars ~= Variant("Jan");
indices[0]["Month"] = vars.length-1;

Ugly as sin, though, and cumbersome to use. But I used it to add
'properties' to nodes and edges in a graph class (like, adding weight to
edges as double, and names to nodes as strings...) and it worked quite well,
with a few functions to hide the trick away.

But it's sad you can't use Variant directly as a value. You can use it as a
key, sort of:

int[Variant] test;
test[Variant(3)] = 4; // test[3] = 4 does not work
test[Variant("abc")] = 0;
writeln(test[Variant("abc")]); // 0
auto k = test.keys; // crash! Assertion failure: 'impl' on line 3886 in file
'mtype.c'
Top | Discussion index | About this forum | D home