Thread overview
Generic container
May 08, 2010
lurker
May 08, 2010
wrzosk
May 09, 2010
bearophile
May 08, 2010
Hello, first time visiting the newsgroup.

I see in the manual that you can create built-in dictionaries like so:

int[string] foo;

Do you know of a way to store any value in a dictionary? In C# I can do something like this:

Dictionary<string, object> foo;

I need a dictionary that can store any value, indexed by string.

Thanks
May 08, 2010
On 08.05.2010 23:52, lurker wrote:
> Hello, first time visiting the newsgroup.
>
> I see in the manual that you can create built-in dictionaries like so:
>
> int[string] foo;
>
> Do you know of a way to store any value in a dictionary? In C# I can do
> something like this:
>
> Dictionary<string, object>  foo;
>
> I need a dictionary that can store any value, indexed by string.
>
> Thanks
Object[string] foo;
foo["aaa"] = new AAA();
May 09, 2010
wrzosk:
> Object[string] foo;
> foo["aaa"] = new AAA();

In D there is no the automatic boxing present in C#, so that can contain any object, but not any value. If you want to store any value, you need the values of that associative array to be of some kind of Box or Variant, etc. There are variant-like types both in Phobos and Tango, but you have to test if they work well for your purposes because it seems it's easy to put bugs in a Variant implementation.

Bye,
bearophile