Errore del compilatore C2766: “Specializzazione esplicita; "Specialization" è già stato definito "quando si utilizza Boost :: Disable_IF

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

Domanda

Sto cercando di costruire una lezione di modello 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 { ... };

che conterrà un corso interno con a static const int value indicando l'indice dell'argomento del modello (0 per S0, 1 per S1 e così via). A poco a poco, dovrebbe soddisfare la condizione:

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) );

Ho provato a usare boost::disable_if come segue:

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

Ma si traduce in errore quando definisco la specializzazione per S3 ed entrambi S2, S3 sono dello stesso tipo aux::EmptyType (o: definisco la specializzazione per S2 ed entrambi S1, S2 sono dello stesso tipo).

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>          ]

Qualche idea su come risolvere il problema? E se volessi un metodo size_t at<S0>() per dare 0, size_t at<S1>() per dare 1 ...?

Si prega di chiedere se hai bisogno di maggiori informazioni.

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top