digitalmars.D - Array collection ?
- GG (10/10) Feb 09 2010 Actually I use an associative array with name as index, to contain diffe...
- Daniel Keep (4/19) Feb 09 2010 Questions like this belong in the d.learn group.
- Steve Teale (2/4) Feb 09 2010 You could try std.boxer, or std.variant.
- GG (2/2) Feb 10 2010 Sorry for posting at wrong place.
- torhu (8/17) Feb 12 2010 Are you sure it's not simpler to just use a struct?
- Daniel Keep (2/10) Feb 12 2010 Bad torhu: never use doubles for currency values!
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. Thanks !
Feb 09 2010
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. Thanks !Questions like this belong in the d.learn group. If you're using D2, you can use Variant. If you're using D1, and you don't want to use Tango, there's std.boxer.
Feb 09 2010
On Wed, 10 Feb 2010 01:16:53 -0500, GG wrote:I would like to know if it's possible to have a associative array with multiple type as a collection with phobos.You could try std.boxer, or std.variant.
Feb 09 2010
Sorry for posting at wrong place. And thank you for your responses. I will try it and learn it !
Feb 10 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; }
Feb 12 2010
torhu wrote:... struct Foo { int month; // or char[] month, or an enum double profit; double expenses; }Bad torhu: never use doubles for currency values!
Feb 12 2010