AA literals/initialisation

Orvid King blah38621 at gmail.com
Sat Jan 11 20:29:51 PST 2014


On Sat, 11 Jan 2014 22:08:25 -0600, Manu <turkeyman at gmail.com> wrote:

> On 12 November 2013 18:09, Don <x at nospam.com> wrote:
>>
>> On Monday, 11 November 2013 at 11:39:06 UTC, Daniel Murphy wrote:
>>
>>>
>>> "Manu" <turkeyman at gmail.com> wrote in message
>>>
>>> news:mailman.355.1384158631.9546.digitalmars-d at puremagic.com...
>>>
>>>>
>>>> immutable string[string] priorityMap = [
>>>>
>>>> "1" : "blocker",
>>>>
>>>> "2" : "critical",
>>>>
>>>> "3" : "critical",
>>>>
>>>> "4" : "major",
>>>>
>>>> "5" : "major",
>>>>
>>>> "6" : "major",
>>>>
>>>> "7" : "minor",
>>>>
>>>> "8" : "minor",
>>>>
>>>> "9" : "trivial" ];
>>>>
>>>>
>>>>
>>>> main.d(56): Error: non-constant expression ["1":"blocker",  
>>>> "2":"critical",
>>>>
>>>> "3":"critical", "4":"major", "5":"major", "6":"major", "7":"minor",
>>>>
>>>> "8":"minor", "9":"trivial"]
>>>>
>>>>
>>>>
>>>> This is tedious, how long has it been now?
>>>>
>>>> Seriously, static map's are super-important, they should be able to  
>>>> be made
>>>>
>>>> immutable, and also be able to be initialised.
>>>>
>>>>
>>>>
>>>> Maybe this could be factored into the improvements for 2.065?
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> I think yes, it can be done for 2.065.  Someone remind me if we get  
>>> close
>>>
>>> and it isn't done yet.
>>>
>>
>>
>>
>>
>>
>> IIRC the poor performance of array literals and AA literals is because  
>> they're not always >>literals, sometimes they are variables (!) and the  
>> compiler assumes the worst case. You are >>allowed to write:
>>
>>
>>
>> void foo(int some_param)
>>
>> {
>>
>>    immutable string[int] = [ 1: "abc", some_param: "def"];
>>
>> }
>>
>>
>>
>> I wish we could get rid of that silliness entirely.
>>
>>
>>
>>
>>
>> If the members are compile-time expressions, you probably want to mark  
>> the variable as static >>const/static immutable.
>>
>
> I've also had this thought. Logically, you shouldn't need to declare an  
> immutable thing static >(although currently, you do), although the  
> advantage would be a guaranteed compile error if you try >to do  
> something silly like initialise from a variable.

I would disagree with that statement, because it is my understanding of  
immutable that it merely means that the value is not modified after it is  
initialized, it does not however mean that the value is determinate at  
compile-time, nor that it is even the same in all invocations of a  
function.


More information about the Digitalmars-d mailing list