
On Jun 25, 2007, at 11:50 AM, Peter Dimov wrote:
Maurizio Vitale wrote:
In short, the documentation for enable_if shows that it can be used for selecting a class specialization depending on a predicate. Now Intel C++ refuses to do that and the frontend team at Intel believes this is the right thing to do (although they'll look into the issue further for the sake of compatibility with GCC). Their argument is that the SFINAE rule applies to the selection of the overload set for functions only and not to partial specialization for classes.
I think that the compiler is right to reject your code since the predicate doesn't depend on T. The S in SFINAE stands for 'substitution', and no substitution occurs in your predicate. The instantiation of S<B> can fail even without a reference to foo because your second declaration of foo is ill-formed.
Thanks this cleared the issue for me. The following goes through the Intel compiler as well. Instantiation is a bit more cumbersome (but not terrible because in my real code it would happen from within S), but at least is (hopefully) standard compliant. template<typename X> struct S { template<typename T, typename XX, typename Enable=void> struct foo { enum { value=0 }; }; template<typename T, typename XX> struct foo<T, XX, typename enable_if<is_same<XX,A> >::type> { enum { value=1 }; }; };