C++17 cannot beat D surely
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Sat Jun 3 15:18:06 PDT 2017
On 03.06.2017 22:16, Basile B. wrote:
> On Saturday, 3 June 2017 at 19:12:46 UTC, Steven Schveighoffer wrote:
>> On Saturday, 3 June 2017 at 17:32:41 UTC, Andrei Alexandrescu wrote:
>>> On 06/03/2017 01:03 PM, Russel Winder via Digitalmars-d wrote:
>>>> Björn Fahller has done compile time sort in C++17 here http://playfulpr
>>>> ogramming.blogspot.co.uk/2017/06/constexpr-quicksort-in-c17.html
>>>>
>>>> Surely D can do better?
>>>
>>> There is nothing to do really. Just use standard library sort.
>>>
>>> void main() {
>>> import std.algorithm, std.stdio;
>>> enum a = [ 3, 1, 2, 4, 0 ];
>>> static auto b = sort(a);
>>> writeln(b);
>>> }
>>
>> I'd say this deserves a blog post but it would be too short.
>>
>> -Steve
>
> Yes but let's correct the mistake first ;-]
> ...
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.
More information about the Digitalmars-d
mailing list