std :: enable_if: parameter vs template parameter
Estou construindo algum verificador de entrada que precisa ter funções específicas para inteiro e / ou duplo (por exemplo, 'isPrime' só deve estar disponível para números inteiros).
Se eu estou usandoenable_if
como parâmetro está funcionando perfeitamente:
template <class T>
class check
{
public:
template< class U = T>
inline static U readVal(typename std::enable_if<std::is_same<U, int>::value >::type* = 0)
{
return BuffCheck.getInt();
}
template< class U = T>
inline static U readVal(typename std::enable_if<std::is_same<U, double>::value >::type* = 0)
{
return BuffCheck.getDouble();
}
};
mas se eu estou usando como um template paramater (como demonstrado emhttp://en.cppreference.com/w/cpp/types/enable_if )
template <class T>
class check
{
public:
template< class U = T, class = typename std::enable_if<std::is_same<U, int>::value>::type >
inline static U readVal()
{
return BuffCheck.getInt();
}
template< class U = T, class = typename std::enable_if<std::is_same<U, double>::value>::type >
inline static U readVal()
{
return BuffCheck.getDouble();
}
};
então eu tenho o seguinte erro:
error: ‘template<class T> template<class U, class> static U check::readVal()’ cannot be overloaded
error: with ‘template<class T> template<class U, class> static U check::readVal()’
Eu não consigo descobrir o que está errado na segunda versão.