Re: Is using function() in templates possible at all?

2018-04-12 Thread Laurent Tréguier via Digitalmars-d-learn
On Thursday, 12 April 2018 at 11:53:21 UTC, Alex wrote: On Thursday, 12 April 2018 at 11:17:01 UTC, Laurent Tréguier wrote: If the function is declared with explicit parameter types: There are cool things possible, if the param type is explicitly typed :) ´´´ import std.traits; void

Re: Is using function() in templates possible at all?

2018-04-12 Thread Laurent Tréguier via Digitalmars-d-learn
On Thursday, 12 April 2018 at 00:05:26 UTC, Nicholas Wilson wrote: There is, with template constraints: class SortedList(T, alias comparer) if(is(typeof(comparer(T.init) : int)) { //... } If the function is declared with explicit parameter types: ``` auto list = new

Re: Is using function() in templates possible at all?

2018-04-11 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 11 April 2018 at 22:13:33 UTC, Sjoerd Nijboer wrote: On Wednesday, 11 April 2018 at 21:29:27 UTC, Alex wrote: I would say, alias template parameter is your friend. https://dlang.org/spec/template.html#TemplateAliasParameter class SortedList(T, alias comparer) It works, thank

Re: Is using function() in templates possible at all?

2018-04-11 Thread Sjoerd Nijboer via Digitalmars-d-learn
On Wednesday, 11 April 2018 at 21:29:27 UTC, Alex wrote: I would say, alias template parameter is your friend. https://dlang.org/spec/template.html#TemplateAliasParameter class SortedList(T, alias comparer) It works, thank you! But just to be shure, there's no way to have this more strongly

Re: Is using function() in templates possible at all?

2018-04-11 Thread Alex via Digitalmars-d-learn
On Wednesday, 11 April 2018 at 21:07:03 UTC, Sjoerd Nijboer wrote: class SortedList(T, int function(T) comparer) I would say, alias template parameter is your friend. https://dlang.org/spec/template.html#TemplateAliasParameter ´´´ import std.stdio; import std.range; void main() {

Is using function() in templates possible at all?

2018-04-11 Thread Sjoerd Nijboer via Digitalmars-d-learn
I am trying to do a binary insert into my sorted array. To sort classes and structs I would like to give a delegate `(t) => t.myValue` to sort on that value whitout having to implement an interface or specifically declare opCmp for every class I want to have sorted. After all, I might want one