MSVC ++ 2012 CTP与可变参数模板挣扎

时间:2013-10-01 21:42:02

标签: c++ visual-studio-2012 c++11 variadic-templates

我的目标是创建一个函子类型类,它可以保存函数的参数,以便它可以在以后执行它。我们的想法是将参数打包到tuple中,然后将它们解压缩到func函数中。这是一个带有一些复制/移动问题的抛出示例,但它现在可以做到。 MSVC ++ 2012 CTP编译器正在努力使用以下代码。

#include <tuple>
#include <string>

using namespace std;

template<int... I> 
struct Sequence {};

//make this pass the package to func, which will do nothing with it
template<typename... Args>
struct Dispatcher{
    //A tuple that holds all of the arguments
    tuple<Args...> argPackage;

    //A constructor that fills the tuple with arguments
    template<typename... CArgs>
    Dispatcher(CArgs&&... args) : argPackage(forward<Args>(args)...) {}

    //A function that takes the arguments and does nothing
    template<typename... Args> 
    void func(Args&&... args){}

    //A function that unpackes the tuple into func(), MSVC can't do this but GCC can
    template<int... I>
    void dispatch(Sequence<I...>){ //line 25
        func(forward<Args>(get<I>(argPackage))...); 
    }
};

int main(){
    Dispatcher<string,string,string> d("str1","str2","str3");
    d.dispatch(Sequence<2,1,0>());
    system("pause");
}

编译器给出了这个错误:

1>c:\users\jeremy\documents\visual studio 2012\projects\test\test\main.cpp(25): fatal error C1001: An internal error has occurred in the compiler.
1>  (compiler file 'msc1.cpp', line 1453)
1>   To work around this problem, try simplifying or changing the program near the locations listed above.

现在,在它的辩护中,编译器会说出以下警告。

  

Microsoft Visual C ++编译器2012年11月“CTP”用于测试目的   仅

我没有使用g++测试这个确切的代码,但我的主项目已由g++成功编译,在更复杂的情况下包含相同的方法。

我可以做些什么来使编译器上的调度功能更容易,这样它就不会吓坏了?我是否应该手动将调度功能展开到某个点而不是将其作为一个vardiadic模板?如果是这样,我如何手动解压Args类型一次?

0 个答案:

没有答案