c++ - GCC: Function wrapper template troubles -


i on gcc 5.3 trying function wrapper code work works fine on clang. here boiled down example:

#include <iostream> using namespace std;  template<class sig, sig f> struct functionwrapper;   template<class ret, class... args, ret (*func)(args...)> struct functionwrapper<ret(args...), func> { };  static int testfunc(int _a, int _b) {     return _a + _b; }   int main() {     functionwrapper<int(int, int), testfunc> wrapper;     return 0; } 

the error on gcc following:

prog.cpp:9:46: error: 'ret(args ...)' not valid type template non-type parameter struct functionwrapper ^ prog.cpp: in function 'int main()': prog.cpp:20:45: error: 'int(int, int)' not valid type template non-type parameter functionwrapper wrapper;

any ideas how make work on both, clang , gcc?

thanks!

i think gcc bug. according [temp.param]:

a non-type template-parameter of type “array of t” or of function type t adjusted of type “pointer t”.

having ret(args...) template non-type parameter equivalent having ret(*)(args...) template non-type parameter.

note gcc [correctly] compile following example, same idea original version:

static int testfunc(int _a, int _b) {     return _a + _b; }  template <int f(int, int)> struct foo { };   int main() {     foo<testfunc> wrapper;     return 0; } 

as workaround, forcing non-type argument pointer allowed both compilers:

template<class sig, sig* f> struct functionwrapper;   template<class ret, class... args, ret (*func)(args...)> struct functionwrapper<ret(args...), func> { }; 

but don't believe should have been necessary.