When compiled with g++ using C++-11, the following code snippet does not compile:
class A
{
public:
template <typename T, typename = typename std::enable_if<T::value>::type>
A(T const &);
template <typename T, typename = typename std::enable_if<!T::value>::type>
A(T const &);
};
Specifically, I get a redefinition error on the second constructor. However, this snippet compiles fine:
class A
{
public:
template <typename T>
A(T const &, typename std::enable_if<T::value>::type * = nullptr);
template <typename T>
A(T const &, typename std::enable_if<!T::value>::type * = nullptr);
};
All I've done is move the enable_if
from the template list to the parameter list. Given this:
(1) What specific rule in the standard allows the second but not the first?
(2) What is the underlying rationale for the two snippets to be treated differently?
Aucun commentaire:
Enregistrer un commentaire