Re: How to declare "type of function, passed as an argument, which should have it's type inferred"? (or if D had an "any" type)

2021-03-29 Thread evilrat via Digitalmars-d-learn
On Monday, 29 March 2021 at 17:52:13 UTC, Gavin Ray wrote: Trying to read this function signature: void my_func(T, XS)(string a, string b, string c, lazy T function(XS)[] t...) Does this say "Generic void function 'my_func', which takes two generic/type params "T" and "XS", and is a

Re: How to declare "type of function, passed as an argument, which should have it's type inferred"? (or if D had an "any" type)

2021-03-29 Thread Gavin Ray via Digitalmars-d-learn
On Monday, 29 March 2021 at 17:02:40 UTC, evilrat wrote: Also with delegates (lazy), you get the type checks however you must have to declare parameters on call site, which can be PITA in the future when doing refactoring will be necessary. Better plan ahead as the number of changes will

Re: How to declare "type of function, passed as an argument, which should have it's type inferred"? (or if D had an "any" type)

2021-03-29 Thread Gavin Ray via Digitalmars-d-learn
On Monday, 29 March 2021 at 16:31:49 UTC, Paul Backus wrote: On Monday, 29 March 2021 at 16:20:59 UTC, Ali Çehreli wrote: auto myFunc(F)(string name, F func) { // This condition could be a template constraint but they don't // support error messages. static assert (is (Parameters!func

Re: How to declare "type of function, passed as an argument, which should have it's type inferred"? (or if D had an "any" type)

2021-03-29 Thread evilrat via Digitalmars-d-learn
On Monday, 29 March 2021 at 15:13:04 UTC, Gavin Ray wrote: Brief question, is it possible to write this so that the "alias fn" here appears as the final argument? auto my_func(alias fn)(string name, string description, auto otherthing) The above seems to work, since the type of "fn" can

Re: How to declare "type of function, passed as an argument, which should have it's type inferred"? (or if D had an "any" type)

2021-03-29 Thread Paul Backus via Digitalmars-d-learn
On Monday, 29 March 2021 at 16:20:59 UTC, Ali Çehreli wrote: auto myFunc(F)(string name, F func) { // This condition could be a template constraint but they don't // support error messages. static assert (is (Parameters!func == AliasSeq!(string)), "'func' must be a

Re: How to declare "type of function, passed as an argument, which should have it's type inferred"? (or if D had an "any" type)

2021-03-29 Thread Ali Çehreli via Digitalmars-d-learn
On 3/29/21 8:13 AM, Gavin Ray wrote: > Brief question, is it possible to write this so that the "alias fn" here > appears as the final argument? > >auto my_func(alias fn)(string name, string description, auto otherthing) Yes, as a type template parameter but you would have to constrain