【发布时间】:2012-07-03 02:03:45
【问题描述】:
我正在使用此代码使用可变参数模板创建多个函数包装器:
// 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;
}
由于已知问题,此代码可以用 clang++ 正确编译,但不能用 g++ 编译:
test.cpp:9:73:抱歉,未实现:无法将“Ts ...”扩展为 定长参数列表
我知道 gcc-4.7 应该能正确处理这个问题,但我现在无法升级......所以我想有一个解决方法来让 Ts... 正确解包。我已经在this one 之类的问题中测试了这里的建议,但他们似乎没有解决这里的问题。
【问题讨论】:
-
当我实际上试图滥用可变参数模板时,我曾经看到过同样的错误,并且升级没有帮助(修复代码)。只是提到
-
顺便说一句,为什么 sigc++ 不是 std::function?
-
@Kos 我正在开发一个使用 sigc::slot 作为基础的框架...
标签: c++ gcc c++11 g++ variadic-templates