2012-10-04 5 views
10

コード

は私の問題のSSCCE例です。テンプレートテンプレートクラスはMSVC++コンパイラに失敗します。ここではC3201

// My Library, which I want to take in the user's enum and a template class which they put per-enum specialized code 
template <typename TEnum, template <TEnum> class EnumStruct> 
struct LibraryT { /* Library stuff */ }; 

// User Defined Enum and Associated Template (which gets specialized later) 
namespace MyEnum { 
    enum Enum { 
     Value1 /*, ... */ 
    }; 
}; 

template <MyEnum::Enum> 
struct MyEnumTemplate {}; 

template <> 
struct MyEnumTemplate<MyEnum::Value1> { /* specialized code here */ }; 

// Then the user wants to use the library: 
typedef LibraryT<MyEnum::Enum, MyEnumTemplate> MyLibrary; 

int main() { 
    MyLibrary library; 
} 

[EDITLibraryT<typename MyEnum::Enum, MyEnumTemplate>LibraryT<MyEnum::Enum, MyEnumTemplate>を変更すると効果がありません]

エラー

私が望む機能列挙型とその列挙型に特化したクラスに基づいてライブラリを作成する能力です。上記は私の最初の試みです。私はそれが100%C++であると信じています。そして、GCCは私をバックアップし、それがすべて動作すると言います。しかし、私はそれがMSVC++コンパイラでコンパイルしたい、それが拒否する:

error C3201: the template parameter list for class template 'MyEnumTemplate' 
    does not match the template parameter list for template parameter 'EnumStruct' 

質問

私はMSVC++コンパイラを作ることができるいくつかの方法があります[EDIT:MSVC++ 11コンパイラ(2012 VS)]私のコードのように?いくつかの追加仕様または異なるアプローチのどちらかによって?

ソリューションの可能性(望ましくない)

ハードコード列挙型は、いくつかの整数型(基本となる型)をするように。その後、問題はありません。しかし、その後、私のライブラリではなく、列挙型(望ましくないが、作業)

// My Library, which I want to take in the user's enum and a template class which they put per-enum specialized code 
typedef unsigned long IntegralType; // **ADDED** 

template <template <IntegralType> class EnumStruct> // **CHANGED** 
struct LibraryT { /* Library stuff */ }; 

// User Defined Enum and Associated Template (which gets specialized later) 
namespace MyEnum { 
    enum Enum { 
     Value1 /*, ... */ 
    }; 
}; 

template <IntegralType> // **CHANGED** 
struct MyEnumTemplate {}; 

template <> 
struct MyEnumTemplate<MyEnum::Value1> {}; 

// Then the user wants to use the library: 
typedef LibraryT<MyEnumTemplate> MyLibrary; // **CHANGED** 

int main() { 
    MyLibrary library; 
} 
+0

結局のところ、VC++ 2010または2012ですか? – ildjarn

+0

@idjarn最新のもの:MSVC++ 11コンパイラ(VS 2012に含まれています) –

+0

@ahendersonこの場合、 'typename'部分はオプションで、それを加えても違いはありません –

答えて

3

の積分で動作しているこれは、Visual C++コンパイラでの既知のバグです。

C++ compiler bug - cannot use template parameters inside nested template declaration

推奨される回避策は、のために整数型を使用することです:(REPROは少し異なりますが、問題は事実上同じである)詳細については、Microsoft Connectの次のバグを参照してください。テンプレートテンプレートパラメータのテンプレートパラメータです。これは、「可能な(しかし望ましくない)解決策」で行ったことです。

関連する問題