Re: The syntax of sort and templates

2017-05-26 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Friday, 26 May 2017 at 15:49:06 UTC, Ali Çehreli wrote: For example, Stroustrup has the article "Learning Standard C++ as a New Language"[1]. It compares sorting performance of C to C++ in section 3, "Efficiency". With those old C and C++ compilers he used (in May 1999), C++ was 1.74 to 4.62

Re: The syntax of sort and templates

2017-05-26 Thread Ali Çehreli via Digitalmars-d-learn
On 05/26/2017 05:10 AM, Patrick Schluter wrote: > in C, where sorting is done via the qsort() function. The comparison > function must be provided by a function pointer. This means that the > qsort function must call a function for doing even the simplest > comparison. For example, Stroustrup ha

Re: The syntax of sort and templates

2017-05-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 26 May 2017 at 11:05:37 UTC, Gary Willoughby wrote: The exclamation mark here is not a binary operator, it's used in D templates to define where compile-time parameters are. It actually is a binary operator, its left-hand-side is a template and its right-hand-side is a template argu

Re: The syntax of sort and templates

2017-05-26 Thread Patrick Schluter via Digitalmars-d-learn
On Friday, 26 May 2017 at 09:59:26 UTC, zakk wrote: Hello everyone, I just started using D and I am a bit puzzled by the syntax of the sort function is std.algorithm.sorting, which is sort!(comparingFunction)(list) where comparingFunction is often a lambda expression. For instance in the Wo

Re: The syntax of sort and templates

2017-05-26 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 26 May 2017 at 11:27:19 UTC, zakk wrote: I have a followup question: my background is C and in Wolfram Mathematica, so my knowledge of templates is limited to trivial examples in C++, like: template const T& min(const T& lhs, const T& rhs) { return lhs < rhs ? lhs : rhs; } wh

Re: The syntax of sort and templates

2017-05-26 Thread nkm1 via Digitalmars-d-learn
On Friday, 26 May 2017 at 11:27:19 UTC, zakk wrote: I have a followup question: my background is C and in Wolfram Mathematica, so my knowledge of templates is limited to trivial examples in C++... It seems to me that when programming in D templates are something more powerful Even in C++ temp

Re: The syntax of sort and templates

2017-05-26 Thread zakk via Digitalmars-d-learn
On Friday, 26 May 2017 at 11:18:44 UTC, Stanislav Blinov wrote: On Friday, 26 May 2017 at 09:59:26 UTC, zakk wrote: Hello everyone, I just started using D and I am a bit puzzled by the syntax of the sort function is std.algorithm.sorting, which is sort!(comparingFunction)(list) where compar

Re: The syntax of sort and templates

2017-05-26 Thread Mike Parker via Digitalmars-d-learn
On Friday, 26 May 2017 at 09:59:26 UTC, zakk wrote: My questions are: 1) Why is D making using of the binary ! operator, which as far as I understand introduces a template? The ! operator *instantiates* a template. Whenever you need to specify compile-time arguments to match the template pa

Re: The syntax of sort and templates

2017-05-26 Thread Stanislav Blinov via Digitalmars-d-learn
On Friday, 26 May 2017 at 09:59:26 UTC, zakk wrote: Hello everyone, I just started using D and I am a bit puzzled by the syntax of the sort function is std.algorithm.sorting, which is sort!(comparingFunction)(list) where comparingFunction is often a lambda expression. For instance in the Wo

Re: The syntax of sort and templates

2017-05-26 Thread Gary Willoughby via Digitalmars-d-learn
On Friday, 26 May 2017 at 09:59:26 UTC, zakk wrote: 1) Why is D making using of the binary ! operator, which as far as I understand introduces a template? The exclamation mark here is not a binary operator, it's used in D templates to define where compile-time parameters are. 2) Why is a te

The syntax of sort and templates

2017-05-26 Thread zakk via Digitalmars-d-learn
Hello everyone, I just started using D and I am a bit puzzled by the syntax of the sort function is std.algorithm.sorting, which is sort!(comparingFunction)(list) where comparingFunction is often a lambda expression. For instance in the Wolfram Language the equivalent function is Sort[list