1

私の目標は、後で実行できるように関数のパラメーターを保存できるファンクター型クラスを作成することです。アイデアは、引数を にパックしてから、それらを関数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その場合、一度に 1 つずつタイプを手動でアンパックするにはどうすればよいですか?

4

0 に答える 0