Implicit conversions for AA keys

Timon Gehr timon.gehr at gmx.ch
Fri Mar 23 14:07:23 PDT 2012


On 03/23/2012 09:43 PM, Andrei Alexandrescu wrote:
> On 3/23/12 3:23 PM, Timon Gehr wrote:
>> On 03/23/2012 09:05 PM, Andrei Alexandrescu wrote:
>>> On 3/23/12 2:28 PM, Timon Gehr wrote:
>>>> On 03/23/2012 08:06 PM, Andrei Alexandrescu wrote:
>>>>>
>>>>> Casting is very different from to, and useless for your purposes. You
>>>>> must use to.
>>>>>
>>>>>
>>>>> Andrei
>>>>
>>>> druntime mustn't depend on Phobos, and I don't see why it is necessary.
>>>> What kind of functionality do you want to provide that depends on
>>>> std.conv.to ?
>>>
>>> Casting from char[] to string is not what you want, and .idup is
>>> specific to arrays. There must be one coherent method of "truely"
>>> converting across types, and std.conv.to is the closest I can think of.
>>>
>>> Andrei
>>
>> This will statically allow looking up an int in a T[string].
>
> No, because of the other rules.
>
> Andrei

I see. An alternative solution (one that does not make AAs depend on 
Phobos and is more slick) would be to use the const qualified key type 
for lookup (that is what const is for) and to have immutable keys for 
stores. For types that define .idup, there would be another overload of 
opIndexAssign that can take a const qualified key.


More information about the Digitalmars-d mailing list