Thread overview | ||||||
---|---|---|---|---|---|---|
|
May 03, 2016 what is equivalent to template template | ||||
---|---|---|---|---|
| ||||
C++ has template templates. I'm not sure how to achieve the same effect where (in example below) the template function myVariadic is passed to another function. void myVaridatic(A...)(A a) {} static void call(alias F,A...)(F f,A a) { f(a); } void foo() { call(myVaridatic,1,2,3); } |
May 03, 2016 Re: what is equivalent to template template | ||||
---|---|---|---|---|
| ||||
Posted in reply to Erik Smith | On 03.05.2016 23:31, Erik Smith wrote: > void myVaridatic(A...)(A a) {} Aside: I think it's "variadic", not "varidatic". > > static void call(alias F,A...)(F f,A a) { static void call(alias f, A...)(A a) { > f(a); > } > > void foo() { > call(myVaridatic,1,2,3); call!myVaridatic(1, 2, 3); > } |
May 03, 2016 Re: what is equivalent to template template | ||||
---|---|---|---|---|
| ||||
Posted in reply to Erik Smith | On Tuesday, 3 May 2016 at 21:31:35 UTC, Erik Smith wrote:
> C++ has template templates. I'm not sure how to achieve the same effect where (in example below) the template function myVariadic is passed to another function.
>
> void myVaridatic(A...)(A a) {}
>
> static void call(alias F,A...)(F f,A a) {
> f(a);
> }
>
> void foo() {
> call(myVaridatic,1,2,3);
> }
You're close.
An `alias` template parameter can be any symbol, including a template. But you can't pass in a template as a runtime parameter, so having `F f` in your parameters list is wrong (there's nothing to pass anyway; you already have the template, which is F).
static void call(alias F, A...)(A a) {
F(a);
}
Then instantiate and call the `call` function with the template you want:
call!myVariadict(1,2,3);
|
May 03, 2016 Re: what is equivalent to template template | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alex Parrill | > You're close.
>
> An `alias` template parameter can be any symbol, including a template. But you can't pass in a template as a runtime parameter, so having `F f` in your parameters list is wrong (there's nothing to pass anyway; you already have the template, which is F).
>
> static void call(alias F, A...)(A a) {
> F(a);
> }
>
> Then instantiate and call the `call` function with the template you want:
>
> call!myVariadict(1,2,3);
Works. Thanks!
|
Copyright © 1999-2021 by the D Language Foundation