Rectangular or 2d associative arrays

Falk Henrich schreibmalwieder at hammerfort.de
Fri Mar 16 15:21:29 PDT 2007


Frits van Bommel wrote:

> Falk Henrich wrote:
>> David Freitas wrote:
>> 
>>>          int[char] x;         // Visually: = ['a':1, 'b':2] //
>>>          associative array x['b'] = 123;
>>>          writefln(x);  // this prints out: [b:2063597568]
>>>          writefln(x['b']); // this prints out: 123
>>>
>>> This just doesn't seem intuitive to me? Why is there a "garbage" value
>>> being printed out?
>> 
>> What would you expect D to print out? How can the language know how to
>> interpet arrays of some type? Hard coding some special output format for
>> all types of arrays into the language is not a wise idea.
> 
> Writef(ln) and other functions that do formatting use the TypeInfo
> provided by their varargs to construct readable representations of their
> parameters. This case just seems to be buggy.

I wasn't aware of that possibility (TypeInfo). Knowing this, the original
question has more sense...

Falk



More information about the Digitalmars-d-learn mailing list