C++17 cannot beat D surely

Basile B. via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 3 20:11:13 PDT 2017


On Saturday, 3 June 2017 at 20:29:04 UTC, Stanislav Blinov wrote:
> On Saturday, 3 June 2017 at 20:18:59 UTC, Basile B. wrote:
>> On Saturday, 3 June 2017 at 18:45:56 UTC, Jacob Carlborg wrote:
>>> On 2017-06-03 20:31, Russel Winder via Digitalmars-d wrote:
>>>
>>>> But is this sort guaranteed to happen at compile time rather 
>>>> than
>>>> runtime?
>>>
>>> Yes. It's the context that decides if it occurs at compile 
>>> time or at runtime.
>>>
>>> Something declared as "static" or "enum" requires that the 
>>> value can be evaluated at compile time.
>>
>> Meeep. Wrong. The example is just wrong. 'static auto b = ...' 
>> is not a compile-time variable. It's just a variable that's 
>> like a global but declared within a function.
>> Remember the singleton pattern using 'static Stuff instance'.
>
> Meep. Wrong :)
>
> Static initializers for static variables and constants are 
> evaluated at compile time, initializing them with runtime 
> values is a compile-time error.
> Yes, you can't do a static assert on b. It's still initialized 
> at compile time though.

Actually i know where my error comes from. It comes from "static 
immutable".
Since "static immutable" can be used in place of "enum" i've 
assumed that this was the real intention and not "static auto...".


More information about the Digitalmars-d mailing list