digitalmars.D.learn - aliasing functions with function arguments as well ??
- james.p.leblanc (16/32) Aug 13 2021 Dear All,
- Steven Schveighoffer (11/50) Aug 13 2021 There isn't a way to alias it. You can wrap it though, and hope the
- james.p.leblanc (8/18) Aug 13 2021 Steve,
Dear All, How does one use 'alias' to incorporate function arguments as well? (I believe this is possible, from some of the examples of aliasSeq, and the traits.Parameters documentation. However, I was unable to come up with anything that works.) What should replace the question marks (???) below?double bar( int a, double x){ return a*x: }template foo(T){ static if ( is(T==int) ){ alias ??? = ??? } else{ alias ??? = ??? } } // when T == int, I desire the aliasing to produce resulting code: foo( int a) = bar( int a, 42.33); // when T == double, I desire: foo( double x) = bar( 7, x);Thanks kindly for any information! James PS I am aware of the "struct holding a function allowing multiple dispatch concept" ... while that would fit quite okay here in my simple example, it isn't appropriate for my real use.
Aug 13 2021
On 8/13/21 11:04 AM, james.p.leblanc wrote:Dear All, How does one use 'alias' to incorporate function arguments as well? (I believe this is possible, from some of the examples of aliasSeq, and the traits.Parameters documentation. However, I was unable to come up with anything that works.) What should replace the question marks (???) below?There isn't a way to alias it. You can wrap it though, and hope the inliner takes care of the difference: ```d auto foo(T)(T arg) { static if(is(T == int)) return bar(arg, 42.33); else return bar(7, arg); } ``` -Stevedouble bar( int a, double x){ return a*x: }template foo(T){ static if ( is(T==int) ){ alias ??? = ??? } else{ alias ??? = ??? } } // when T == int, I desire the aliasing to produce resulting code: foo( int a) = bar( int a, 42.33); // when T == double, I desire: foo( double x) = bar( 7, x);Thanks kindly for any information! James PS I am aware of the "struct holding a function allowing multiple dispatch concept" ... while that would fit quite okay here in my simple example, it isn't appropriate for my real use.
Aug 13 2021
On Friday, 13 August 2021 at 15:14:00 UTC, Steven Schveighoffer wrote:There isn't a way to alias it. You can wrap it though, and hope the inliner takes care of the difference: ```d auto foo(T)(T arg) { static if(is(T == int)) return bar(arg, 42.33); else return bar(7, arg); } ``` -SteveSteve, Thanks! Yes ... this templated wrapper should be perfect for me! Your help on my present question, as well as your continual contributions to the forum are greatly appreciated! Best Regards, James
Aug 13 2021