/* This code normally fails to compile under Visual Studio 2012 The fix is marked with _MSC_VER */ #include #include template struct has_lowest_layer_type { typedef char yes; typedef struct {char dummy[2];} no; template static yes f(typename C::lowest_layer_type*); template static no f(...); #ifdef _MSC_VER static const bool value = sizeof(f(0)) == 1; #else static const bool value = sizeof(has_lowest_layer_type::f(0)) == 1; #endif }; template struct EnableIf : std::false_type { }; template <> struct EnableIf : std::true_type { }; struct tcp { }; template struct basic_socket { typedef basic_socket lowest_layer_type; }; template struct basic_stream_socket : basic_socket { typedef basic_socket next_layer_type; }; struct A { typedef basic_socket lowest_layer_type; }; struct B { }; template void show (std::true_type) { std::cout << typeid(T).name() << " has lowest_layer_type" << std::endl; } template void show (std::false_type) { std::cout << typeid(T).name() << " does not have lowest_layer_type" << std::endl; } template void show () { show (EnableIf ::value> ()); } int main () { show (); show (); show > (); show > (); return 0; } /* 1>..\..\Subtrees\beast\notes\1\test.cpp(16): error C2783: 'has_lowest_layer_type::no has_lowest_layer_type::f(...)' : could not deduce template argument for 'C' 1> with 1> [ 1> T=A 1> ] 1> ..\..\Subtrees\beast\notes\1\test.cpp(15) : see declaration of 'has_lowest_layer_type::f' 1> with 1> [ 1> T=A 1> ] 1> ..\..\Subtrees\beast\notes\1\test.cpp(63) : see reference to class template instantiation 'has_lowest_layer_type' being compiled 1> with 1> [ 1> T=A 1> ] 1> ..\..\Subtrees\beast\notes\1\test.cpp(68) : see reference to function template instantiation 'void show(void)' being compiled */