Thread overview | |||||
---|---|---|---|---|---|
|
May 14, 2004 Functions as parameters in templates. | ||||
---|---|---|---|---|
| ||||
Walter Wrote: >> >>I wish D templates could accept operators/functions as parameters. >> >> >> >> > > > > >> > >> >It can accept functions as parameters - both as function pointers, >> and as >> >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. > How could you pass in the operator for say - integers then? -- -Anderson: http://badmama.com.au/~anderson/ |
May 14, 2004 Re: Functions as parameters in templates. | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | "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.... > > You can use the equivalent name for the operator functions. > How could you pass in the operator for say - integers then? If class Foo has an opAdd() function, use an alias parameter for Foo.opAdd. |
May 15, 2004 Re: Functions as parameters in templates. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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; > > Yeah I tried that as well. >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/ |
Copyright © 1999-2021 by the D Language Foundation