Tre*_*iño 1 c++ gcc g++ variadic-templates c++11
我正在使用此代码使用可变参数模板创建多个函数包装器:
// Compile with g++ -std=c++0x $(pkg-config sigc++-2.0 --cflags --libs) test.cpp -o test
#include <iostream>
#include <type_traits>
#include <sigc++/sigc++.h>
template <typename R, typename G, typename... Ts>
class FuncWrapper
{
public:
FuncWrapper(G object, std::string const& name, sigc::slot<R, Ts...> function) {};
};
int main()
{
FuncWrapper<void, int, int, bool, char> tst(0, "test", [] (int a, bool b, char c) {});
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
由于已知问题,此代码正确编译了clang ++,但没有使用g ++编译:
test.cpp:9:73:抱歉,未实现:无法将'Ts ...'扩展为固定长度的参数列表
我知道gcc-4.7应该正确处理,但我现在无法升级...所以我想要一个解决方法来Ts...正确解压缩.我测试过什么样的问题在这里提出这一个,但他们似乎并不在这里解决问题.
您可以使用以下方法解决错误:
template<template <typename...> class T, typename... Args>
struct Join
{ typedef T<Args...> type; };
Run Code Online (Sandbox Code Playgroud)
然后替换sigc::slot<R, Ts...>用typename Join<sigc::slot, R, Ts...>::type
(感谢Chris Jefferson关于GCC错误报告的建议)