コンパイラエラーC2766:「明示的な専門化。 boost :: disable_ifを使用する場合、「専門化」がすでに定義されています」

StackOverflow https://stackoverflow.com/questions/8924325

質問

テンプレートクラスを作成しようとしています Fod

template<typename S0 = aux::EmptyType, typename S1 = aux::EmptyType, typename S2 = aux::EmptyType, typename S3 = aux::EmptyType, typename S4 = aux::EmptyType, typename S5 = aux::EmptyType, typename S6 = aux::EmptyType, typename S7 = aux::EmptyType, typename S8 = aux::EmptyType, typename S9 = aux::EmptyType>
class Fod { ... };

で内側のクラスが含まれます static const int value テンプレート引数のインデックスを示します(S0の場合は0、S1の場合は1など)。まもなく、条件を満たす必要があります。

struct Type0 {}; struct Type1 {};
BOOST_STATIC_ASSERT( (Fod<Type0>::At<Type0>::value == 0) );
BOOST_STATIC_ASSERT( (Fod<Type0, Type1>::At<Type0>::value == 0) );
BOOST_STATIC_ASSERT( (Fod<Type0, Type1>::At<Type1>::value == 1) );

使ってみました boost::disable_if 次のように:

template<class T, class Enable = void>
class At; // undefined

template<>
struct At<S0, typename boost::disable_if<boost::is_same<S0, aux::EmptyType> >::type > {
    static const int value = 0;
};

template<>
struct At<S1, typename boost::disable_if<boost::is_same<S1, aux::EmptyType> >::type > {
    static const int value = 1;
};

template<>
struct At<S2, typename boost::disable_if<boost::is_same<S2, aux::EmptyType> >::type > {
    static const int value = 2;
};

template<>
struct At<S3, typename boost::disable_if<boost::is_same<S3, aux::EmptyType> >::type > {
    static const int value = 3;
};

// and so on for S4...S9

しかし、S3と両方のS2、S3の専門化を定義すると同じタイプがあります。 aux::EmptyType (または:S2の専門化を定義し、両方のS1、S2は同じタイプです)。

4>C:\phd\cpp\src\boost/dst/fod.hpp(144): error C2766: explicit specialization ; 'boost::dst::fod<S0>::At<boost::dst::aux::EmptyType,boost::mpl::s_item<T,Base>>' has already been defined
4>          with
4>          [
4>              S0=Type0
4>          ]
4>          and
4>          [
4>              T=Type0,
4>              Base=boost::mpl::set0<>::item_
4>          ]

問題を解決する方法はありますか?そして、私が方法が欲しかったら size_t at<S0>() 0を与えるには、 size_t at<S1>() 1を与えるために...?

詳細情報が必要かどうか尋ねてください。

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top