digitalmars.D - Functions as parameters in templates.
- J Anderson <REMOVEanderson badmama.com.au> May 14 2004
- "Walter" <newshound digitalmars.com> May 14 2004
- J Anderson <REMOVEanderson badmama.com.au> May 14 2004
Walter Wrote:I wish D templates could accept operators/functions as parameters.
It can accept functions as parameters - both as function pointers,
aliases.
Let me get this straight. What is the syntax? I tried this: template tempT(alias func) { void temp() { func(); } } void myfunc() { } alias tempT!(myfunc).temp() foo; int main( char[][] args ) { foo(); return 0; }
Cool, now for operators....
You can use the equivalent name for the operator functions.
-- -Anderson: http://badmama.com.au/~anderson/
May 14 2004
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:c8308u$105q$4 digitaldaemon.com...Let me get this straight. What is the syntax? I tried this: template tempT(alias func) { void temp() { func(); } } void myfunc() { } alias tempT!(myfunc).temp() foo;
use: alias tempT!(myfunc).temp foo; Unfortunately, there's a bug preventing that from working, which will be fixed in the next update.int main( char[][] args ) { foo(); return 0; }Cool, now for operators....
If class Foo has an opAdd() function, use an alias parameter for Foo.opAdd.
May 14 2004
Walter wrote:"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:c8308u$105q$4 digitaldaemon.com...Let me get this straight. What is the syntax? I tried this: template tempT(alias func) { void temp() { func(); } } void myfunc() { } alias tempT!(myfunc).temp() foo;
use: alias tempT!(myfunc).temp foo;
Unfortunately, there's a bug preventing that from working, which will be fixed in the next update.
-- -Anderson: http://badmama.com.au/~anderson/
May 14 2004








J Anderson <REMOVEanderson badmama.com.au>