www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Multi-Dimensional Associative Arrays ".get" and "in"

reply "Paul" <phshaffer gmail.com> writes:
I've seen examples using .get and "in" to test for keys:
....aa.get("hello", "salute") == "ciao"....
...."hello" in aa....

Can I use this .get function or "in" operator with multi-D arrays?

string[string][string][string] aa;

....if (["hello"][][] in aa).... ?
Jun 06 2012
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 06/06/2012 04:17 PM, Paul wrote:
 I've seen examples using .get and "in" to test for keys:
 ....aa.get("hello", "salute") == "ciao"....
 ...."hello" in aa....

 Can I use this .get function or "in" operator with multi-D arrays?

 string[string][string][string] aa;

 ....if (["hello"][][] in aa).... ?
Well, no. string[string][string][string] is an associative array mapping strings to associative arrays mapping strings to associative arrays mapping strings to strings. The indexes are more or less unrelated as far as the AA interface is concerned. You can implement such functionality yourself, or use an approach like string[Tuple!(string, string, string)] aa; ....if(tuple("hello","salute","ciao") in aa).... if it is compatible with your usage patterns. this maps 3 key strings to the value string in one go.
Jun 08 2012