[英]Function parameter in variadic template
Is it possible to write a variadic template class with functions as template parameter ? 是否可以编写一个带有函数作为模板参数的可变参数模板类?
Theses are valid c++ declarations 这些是有效的c ++声明
template <typename ...Types> class foo;
template <int func(int)> class bar;
Would it be possible to do something like 是否可以做类似的事情
template <int func(int)...> class foobar;
I tried a lot of different syntax like 我尝试了很多不同的语法
template <int ...func(int)> class foobar;
and nothing is compiling (I am using gcc 8.1.0 with -std=c++17) 并没有编译(我使用gcc 8.1.0与-std = c ++ 17)
Syntax is: 语法是:
template <int (*...Fs)(int)> class foobar {};
which allows 这使得
int f1(int);
int f2(int);
foobar<&f1, &f2, &f1> obj;
Using alias might help you to have more natural syntax: 使用别名可能会帮助您获得更自然的语法:
using f_int_int = int (*)(int);
template <f_int_int...Fs> class foobar {};
or even (thanks to Yakk's comment): 甚至(感谢Yakk的评论):
template <typename T> using id_t = T;
template <id_t<int(*)(int)>...Fs> class foobar {};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.