From 3f26543d6a89a0bd3111c3cbdee5ee9cdf930bb6 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 15 Aug 2013 15:34:12 -0700 Subject: [PATCH] Report notes for issue #1 --- Subtrees/beast/notes/1/test.cpp | 94 +++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Subtrees/beast/notes/1/test.cpp diff --git a/Subtrees/beast/notes/1/test.cpp b/Subtrees/beast/notes/1/test.cpp new file mode 100644 index 0000000000..fc88aea797 --- /dev/null +++ b/Subtrees/beast/notes/1/test.cpp @@ -0,0 +1,94 @@ +/* + 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 +*/