AA key conversion woes

Timon Gehr timon.gehr at gmx.ch
Tue Apr 17 11:59:10 PDT 2012


On 04/17/2012 08:53 PM, H. S. Teoh wrote:
> On Tue, Apr 17, 2012 at 08:48:04PM +0200, Andrej Mitrovic wrote:
>> On 4/17/12, Andrej Mitrovic<andrej.mitrovich at gmail.com>  wrote:
>>> On 4/17/12, H. S. Teoh<hsteoh at quickfur.ath.cx>  wrote:
>>>> But even then, I'm considering if .keys should return a mutable array if
>>>> the key is a value type
>>>
>>> How about having .keys for mutable
>>
>> Personally I use .keys often and expect them to be mutable. For example:
>>
>> string[] atts = attributes.keys;
>> sort(atts);
>>
>> There is no "sorted" in phobos so I have to use the sort function
>> which takes arguments by reference. I can't pass immutable arrays to
>> it.
>>
>> Sometimes I like to store an array of keys from multiple hashes, e.g.:
>> string[] arr = hash.keys;
>> arr ~= hash2.keys;
>>
>> Long story short, making .keys immutable would break a lot of my code.
>> I don't know if that's true for others as well..
>
> What if .keys returns a tail-immutable array? You should still be able
> to sort it, right?
>
>
> T
>

No, an immutable array cannot be sorted regardless of whether or not the 
slice is mutable.


More information about the Digitalmars-d mailing list