digitalmars.D - Functions as parameters in templates.
- J Anderson (17/32) May 14 2004 Let me get this straight. What is the syntax? I tried this:
- Walter (7/23) May 14 2004 use:
- J Anderson (5/28) May 14 2004 That'll help me a lot in simplifying code. Thanks.
Walter Wrote: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; }I wish D templates could accept operators/functions as parameters.It can accept functions as parameters - both as function pointers,and asaliases.How could you pass in the operator for say - integers then? -- -Anderson: http://badmama.com.au/~anderson/Cool, now for operators....You can use the equivalent name for the operator functions.
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; }If class Foo has an opAdd() function, use an alias parameter for Foo.opAdd.How could you pass in the operator for say - integers then?Cool, now for operators....You can use the equivalent name for the operator functions.
May 14 2004
Walter wrote:"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:c8308u$105q$4 digitaldaemon.com...Yeah I tried that as well.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.That'll help me a lot in simplifying code. Thanks. -- -Anderson: http://badmama.com.au/~anderson/
May 14 2004