Re: sort using delegate as predicate

2014-09-16 Thread Justin Whear via Digitalmars-d-learn
On Tue, 16 Sep 2014 16:38:04 +, Simon Bürger wrote: > >> sort!((a,b) => f.cmp(a, b))(data); > > does in fact compile, so i guess problem is solved. Thanks guys. Yes, this compiles because the lambda forms a closure over f. In some respects this might even be better than the C++ as there is

Re: sort using delegate as predicate

2014-09-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 16, 2014 at 04:38:04PM +, via Digitalmars-d-learn wrote: > On Tuesday, 16 September 2014 at 16:27:46 UTC, H. S. Teoh via > Digitalmars-d-learn wrote: > >On Tue, Sep 16, 2014 at 04:19:10PM +, via Digitalmars-d-learn wrote: > >>The following code does not compile, because the cust

Re: sort using delegate as predicate

2014-09-16 Thread via Digitalmars-d-learn
On Tuesday, 16 September 2014 at 16:27:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote: On Tue, Sep 16, 2014 at 04:19:10PM +, via Digitalmars-d-learn wrote: The following code does not compile, because the custom predicate of std.algorithm.sort is a template parameter, and therefore can on

Re: sort using delegate as predicate

2014-09-16 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Sep 16, 2014 at 04:19:10PM +, via Digitalmars-d-learn wrote: > The following code does not compile, because the custom predicate of > std.algorithm.sort is a template parameter, and therefore can only be > a function, but not a delegate. What makes you think so? Template parameters cer

Re: sort using delegate as predicate

2014-09-16 Thread Justin Whear via Digitalmars-d-learn
On Tue, 16 Sep 2014 16:19:10 +, Simon Bürger wrote: > The following code does not compile, because the custom predicate of > std.algorithm.sort is a template parameter, and therefore can only be a > function, but not a delegate. In C++, there is a variant of sort taking > a function-object as

sort using delegate as predicate

2014-09-16 Thread via Digitalmars-d-learn
The following code does not compile, because the custom predicate of std.algorithm.sort is a template parameter, and therefore can only be a function, but not a delegate. In C++, there is a variant of sort taking a function-object as a second (run-time) parameter, but phobos does not seems to h