組み込みアプリケーションで、特定のクラスのメンバー関数へのポインターのリストを保持するヘルパー クラスを作成したいと思います。ヘルパー クラスはメンバー関数を連続して呼び出します。現在、ポインタを保持する静的配列の定義文に問題があります。これはコードです:
template<class C, class F>
struct FunctionSequence;
template<class C, class R, class... Args>
struct FunctionSequence<C, R(Args...)>
{
typedef R(C::*PointerToMember)(Args...);
template<PointerToMember... F>
struct Type
{
static const PointerToMember f[sizeof...(F)];
};
};
template<class C, class R, class... Args>
template<typename FunctionSequence<C, R(Args...)>::PointerToMember... F>
const typename FunctionSequence<C, R(Args...)>::PointerToMember
FunctionSequence<C, R(Args...)>::Type<typename FunctionSequence<C, R(Args...)>::PointerToMember... F>::f[sizeof...(F)]
= { F... };
struct Test
{
void m1(int) {}
void m2(int) {}
FunctionSequence<Test, void(int)>::Type<&Test::m1, &Test::m2> fs;
};
Visual Studio 2013 と GCC 4.7.3 の両方で、f 変数を定義しようとしているこの行でエラーが発生し、メンバー関数ポインターのリストで初期化します。
FunctionSequence<C, R(Args...)>::Type<typename FunctionSequence<C, R(Args...)>::PointerToMember... F>::f[sizeof...(F)]
GCC は次のエラーを返します。
expansion pattern 'typename FunctionSequence<C, R(Args ...)>::PointerToMember' contains no argument packs
too many template-parameter-lists
Visual Studio で次のエラーが発生します。
error C3546: '...' : there are no parameter packs available to expand
error C2146: syntax error : missing ',' before identifier 'F'
error C3545: 'F': parameter pack expects a non-type template argument
さらに、Visual Studio は 1 行後に追加のエラーを返します。
error C3855: 'FunctionSequence<C,R(Args...)>::Type<F...>': template parameter 'F' is incompatible with the declaration
私がやろうとしていることは可能ですか?私のコードは間違っていますか?修正可能ですか?