Array collection ?

torhu no at spam.invalid
Fri Feb 12 09:44:20 PST 2010


On 10.02.2010 07:16, GG wrote:
> Actually I use an associative array with name as index, to contain different data but it allows only string type. It forces me to cast all time.
> ex:
> string[char[]][int] a;
>
> a[0]["Month"] = "Jan";
> a[0]["Profit"] = to!string(1000); // when I want use this as int, I use : to!int()
> a[0]["Expenses"] = "6000"; // when I want use this as int, I use : to!int()
>
> But as you can see, "Profit" and "Expenses" should be int or double to avoid cast when I want calculate these fields.
>
> It works with cast but I suppose it's slower than use exact type.
>
> I would like to know if it's possible to have a associative array with multiple type as a collection with phobos.
>

Are you sure it's not simpler to just use a struct?

struct Foo
{
   int month;  // or char[] month, or an enum
   double profit;
   double expenses;
}



More information about the Digitalmars-d mailing list