www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Append variadic template parameters

reply Mark Fisher <logicfish gmail.com> writes:
I want to write a template:

static auto ref BindArg(alias Func,alias arg,args...)() {
	return Func(arg,args);
}

where Func is called with 'arg' followed by the 'args' parameters.
eg:

string f(string a,int b,int c);
BindArg(f,"1",2,3);

The compiler throws an error:
Error: function f (string a, int b, int c) is not callable using 
argument types ()

How do I append the parameters?
Feb 05
next sibling parent ag0aep6g <anonymous example.com> writes:
On Sunday, 5 February 2017 at 20:36:57 UTC, Mark Fisher wrote:
 static auto ref BindArg(alias Func,alias arg,args...)() {
 	return Func(arg,args);
 }
[...]
 BindArg(f,"1",2,3);
You forgot an exclamation mark there: BindArg!(f,"1",2,3);
Feb 05
prev sibling parent reply Meta <jared771 gmail.com> writes:
On Sunday, 5 February 2017 at 20:36:57 UTC, Mark Fisher wrote:
 I want to write a template:

 static auto ref BindArg(alias Func,alias arg,args...)() {
 	return Func(arg,args);
 }

 where Func is called with 'arg' followed by the 'args' 
 parameters.
 eg:

 string f(string a,int b,int c);
BindArg(f,"1",2,3); You forgot the !
 The compiler throws an error:
 Error: function f (string a, int b, int c) is not callable 
 using argument types ()

 How do I append the parameters?
Feb 05
parent Mark Fisher <logicfish gmail.com> writes:
On Sunday, 5 February 2017 at 21:51:14 UTC, Meta wrote:
 On Sunday, 5 February 2017 at 20:36:57 UTC, Mark Fisher wrote:
 I want to write a template:

 static auto ref BindArg(alias Func,alias arg,args...)() {
 	return Func(arg,args);
 }

 where Func is called with 'arg' followed by the 'args' 
 parameters.
 eg:

 string f(string a,int b,int c);
BindArg(f,"1",2,3); You forgot the !
 The compiler throws an error:
 Error: function f (string a, int b, int c) is not callable 
 using argument types ()

 How do I append the parameters?
doh! Thank you.
Feb 05