Jump to page: 1 25  
Page
Thread overview
C++17 cannot beat D surely
Jun 03, 2017
Russel Winder
Jun 03, 2017
Russel Winder
Jun 03, 2017
Meta
Jun 03, 2017
Jacob Carlborg
Jun 03, 2017
Basile B.
Jun 03, 2017
Stanislav Blinov
Jun 03, 2017
ag0aep6g
Jun 03, 2017
Stanislav Blinov
Jun 04, 2017
Basile B.
Jun 03, 2017
Stanislav Blinov
Jun 03, 2017
Basile B.
Jun 03, 2017
Timon Gehr
Jun 03, 2017
jmh530
Jun 04, 2017
Mike Parker
Jun 04, 2017
Adam D. Ruppe
Jun 04, 2017
Mike Parker
Jun 04, 2017
Mike Parker
Jun 04, 2017
Jonathan M Davis
Jun 04, 2017
Mike Parker
Jun 07, 2017
Yuxuan Shui
Jun 07, 2017
Ali Çehreli
Jun 07, 2017
Ali Çehreli
Jun 07, 2017
Stanislav Blinov
Jun 07, 2017
Walter Bright
Jun 04, 2017
Stefan Koch
Jun 03, 2017
Tourist
Jun 03, 2017
Ali Çehreli
Jun 04, 2017
H. S. Teoh
Jun 04, 2017
Stanislav Blinov
Jun 04, 2017
H. S. Teoh
Jun 04, 2017
Jacob Carlborg
Jun 04, 2017
Jonathan M Davis
Jun 04, 2017
Mike Parker
Jun 05, 2017
Atila Neves
Jun 04, 2017
Russel Winder
Jun 04, 2017
Vittorio Romeo
Jun 04, 2017
rikki cattermole
Jun 04, 2017
Vittorio Romeo
Jun 04, 2017
rikki cattermole
Jun 04, 2017
David Nadlinger
Jun 06, 2017
Era Scarecrow
Jun 06, 2017
Stefan Koch
June 03, 2017
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?

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

June 03, 2017
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);
}

Andrei
June 03, 2017
On Sat, 2017-06-03 at 13:32 -0400, Andrei Alexandrescu via Digitalmars- d wrote:
> […]
> 
> 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);
> }
> 

But is this sort guaranteed to happen at compile time rather than runtime?

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

June 03, 2017
On Saturday, 3 June 2017 at 18:31:37 UTC, Russel Winder wrote:
> On Sat, 2017-06-03 at 13:32 -0400, Andrei Alexandrescu via Digitalmars- d wrote:
>> […]
>> 
>> 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);
>> }
>> 
>
> But is this sort guaranteed to happen at compile time rather than runtime?

Yes: https://dlang.org/spec/function.html#interpretation

And there's no jumping through ridiculous hoops, unlike the article.
June 03, 2017
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. That's the beauty of D, the same functions can be used both at compile time and at runtime.

-- 
/Jacob Carlborg
June 03, 2017
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

June 03, 2017
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

It already looks like a great blog post as is :)
June 03, 2017
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 ;-]

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);
}


June 03, 2017
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'.

June 03, 2017
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.
« First   ‹ Prev
1 2 3 4 5