C++17 cannot beat D surely

Stefan Koch via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 3 20:38:44 PDT 2017


On Saturday, 3 June 2017 at 23:41:37 UTC, jmh530 wrote:
> On Saturday, 3 June 2017 at 22:18:06 UTC, Timon Gehr wrote:
>>
>> There is no mistake. (But 'auto' is redundant.)
>>
>>> void main() {
>>>      import std.algorithm, std.stdio;
>>>      enum a = [ 3, 1, 2, 4, 0 ];
>>>      enum b = sort(a);// static is not CT !!!!!
>>>      static assert(b[0] == 0); // does not pass with static 
>>> auto b...
>>>      writeln(b);
>>> }
>>> 
>>> 
>>
>> This is worse. Now there is an allocation at runtime.
>
> So maybe we can do a blog post on when to use static or enum? 
> Because smart people don't seem to be agreeing on this...

In General, prefer static immutable.



More information about the Digitalmars-d mailing list