Thread overview
const for associative arrays?
Mar 12, 2004
Steve Adams
Mar 12, 2004
Walter
Mar 12, 2004
C. Sauls
Mar 13, 2004
Walter
Mar 13, 2004
Steve Adams
Mar 12, 2004
Phill
March 12, 2004
Is there a way to declare and initialize associative arrays?  Something along the lines of:

   const int[char[]] foo =  list of pairs?

Thanks.
March 12, 2004
"Steve Adams" <adamss@ascinet.com> wrote in message news:40521D81.4030808@ascinet.com...
> Is there a way to declare and initialize associative arrays?  Something along the lines of:
>
>     const int[char[]] foo =  list of pairs?

Currently, there isn't. One way to do it is to use a module constructor to load up the array.


March 12, 2004
I think you will find that info here:

http://www.digitalmars.com/d/arrays.html

Phill.


"Steve Adams" <adamss@ascinet.com> wrote in message news:40521D81.4030808@ascinet.com...
> Is there a way to declare and initialize associative arrays?  Something along the lines of:
>
>     const int[char[]] foo =  list of pairs?
>
> Thanks.


March 12, 2004
When do you think that might become available?  I'm really looking forward to it personally, because I have a lot of those module constructors doing just that, and it would be nice to get it all in one statement.

I'm sure its all been said before, but I'm personally a fan of the : syntax...
const int[char[]] FOO = [
    "abc" : 1,
    "def" : 2,
    "ghi" : 3
];

Feels consistant with the struct syntax, and reminds me of Python all at once.  :)

-C. Sauls
-Invironz

Walter wrote:
> "Steve Adams" <adamss@ascinet.com> wrote in message
> news:40521D81.4030808@ascinet.com...
> 
>>Is there a way to declare and initialize associative arrays?  Something
>>along the lines of:
>>
>>    const int[char[]] foo =  list of pairs?
> 
> 
> Currently, there isn't. One way to do it is to use a module constructor to
> load up the array.
March 13, 2004
Walter wrote:
> "Steve Adams" <adamss@ascinet.com> wrote in message
> news:40521D81.4030808@ascinet.com...
> 
>>Is there a way to declare and initialize associative arrays?  Something
>>along the lines of:
>>
>>    const int[char[]] foo =  list of pairs?
> 
> 
> Currently, there isn't. One way to do it is to use a module constructor to
> load up the array.
> 
> 

Thanks, I'll use that approach.
March 13, 2004
"C. Sauls" <ibisbasenji@yahoo.com> wrote in message news:c2tess$2mki$1@digitaldaemon.com...
> When do you think that might become available?  I'm really looking forward to it personally, because I have a lot of those module constructors doing just that, and it would be nice to get it all in one statement.

Not for 1.0, but better array literals are a good candidate for 2.0.