digitalmars.D.learn - Duplicate another function's parameters in a template function
- Tofu Ninja (24/24) Apr 20 2015 I am trying to write a template function that can take another
- Justin Whear (3/16) Apr 20 2015 See std.functional.forward:
- Tofu Ninja (2/4) Apr 20 2015 Sweet beans, thanks
I am trying to write a template function that can take another function as an alias template argument and duplicate its parameters for it self. For example, something like this... void foo(ref int x){x = 7;} auto pass(alias f)(/* ??? */) { // other stuff... return f( /* ??? */ ); } void main() { int y = 0; pass!foo(y); assert(y==7); } I tried.. auto pass(alias f, T...)(T t) { // other stuff... return f(t); } but that does not work if there is a ref parameter. Thanks
Apr 20 2015
On Mon, 20 Apr 2015 22:50:52 +0000, Tofu Ninja wrote:I am trying to write a template function that can take another function as an alias template argument and duplicate its parameters for it self. I tried.. auto pass(alias f, T...)(T t) { // other stuff... return f(t); } but that does not work if there is a ref parameter. ThanksSee std.functional.forward:
Apr 20 2015
On Monday, 20 April 2015 at 23:20:07 UTC, Justin Whear wrote:See std.functional.forward:Sweet beans, thanks
Apr 20 2015