Search code examples
d

How to declare and initialize an associative array with string as keys and arrays as value


I am new to D. I am looking for the equivalent of this C++ declaration

typedef std::vector<std::string> the_value;
std::map<std::string,the_value> the_table;

Solution

  • You want something like this probably:

    string[][string] the_table;
    

    example:

    import std.stdio;
    
    void main(string[] args)
    {
        string[][string] the_table = ["k1" : ["v1", "v2"], "k2" : ["v3", "v4"]];
        writeln(the_table);
    }