You need to make enable_if dependent on the template parameter. As now, it depends only on the external template parameter in the template definition. But if you create an instance of a class from an external template, then your template of the assignment operator that is created in this class no longer depends on the template parameter, because T will already be replaced.
Just enter a dummy parameter equal to T
template<typename T1 = T, typename = typename std::enable_if< ( !std::is_same< X<T1>, typename StrangerTypeRules<T1>::type >::value ), X<T1> >::type > X<T1> & operator=( const typename StrangerTypeRules <T1>::type& rhs ) { return *this; }
Using T1 only one of the places inside the template arguments enable_if<...> would be sufficient, because it already makes enable_if dependent.
However, this is not a call to your operator= , which was previously unqualified, but its declaration, which conflicts with the copy operator, so enable_if is of little use here. Just replace your code with
template<typename T1 = T> X<T1> & operator=( const typename StrangerTypeRules <T1>::type& rhs ) { return *this; }
Since this operator= is a template, it will not conflict with overloading without templates. And also because this is a pattern, when you call it, the compiler will prefer a non-pattern if T is X<T> .
source share