From e2650b802544e0263739fe9cc583d265724e80fe Mon Sep 17 00:00:00 2001 From: Sergey Podobry Date: Mon, 25 Apr 2022 19:05:55 +0300 Subject: [PATCH] Fix compilation on VS2010 (#207) --- include/plog/Record.h | 53 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/include/plog/Record.h b/include/plog/Record.h index 950a967..7c2092a 100644 --- a/include/plog/Record.h +++ b/include/plog/Record.h @@ -27,6 +27,43 @@ namespace plog template struct enableIf { typedef T type; }; + + struct No { char a[1]; }; + struct Yes { char a[2]; }; + + template + struct isConvertible + { + // `+ sizeof(U*)` is required for GCC 4.5-4.7 + template + static typename enableIf(meta::declval())) + sizeof(U*)), Yes>::type test(int); + + template + static No test(...); + + enum { value = sizeof(test(0)) == sizeof(Yes) }; + }; + + template + struct isConvertibleToNString : isConvertible > {}; + + template + struct isContainer + { + template + static typename meta::enableIf().begin()) + sizeof(meta::declval().end() +#else + typename U::const_iterator +#endif + )), Yes>::type test(int); + + template + static No test(...); + + enum { value = sizeof(test(0)) == sizeof(Yes) }; + }; } ////////////////////////////////////////////////////////////////////////// @@ -88,20 +125,20 @@ namespace plog } #if defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 4 // skip for GCC < 4.5 due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38600 - // Print data that can be casted to `std::basic_string`. `+ sizeof(T*)` is required for GCC 4.5-4.7. - template - inline typename meta::enableIf >(meta::declval())) + sizeof(T*)), void>::type operator<<(util::nostringstream& stream, const T& data) + // Print data that can be casted to `std::basic_string`. + template + inline typename meta::enableIf::value, void>::type operator<<(util::nostringstream& stream, const T& data) { plog::detail::operator<<(stream, static_cast >(data)); } // Print std containers - template - inline typename meta::enableIf::type operator<<(util::nostringstream& stream, const Container& data) + template + inline typename meta::enableIf::value && !meta::isConvertibleToNString::value, void>::type operator<<(util::nostringstream& stream, const T& data) { stream << "["; - for (typename Container::const_iterator it = data.begin(); it != data.end();) + for (typename T::const_iterator it = data.begin(); it != data.end();) { stream << *it; @@ -129,12 +166,12 @@ namespace plog namespace meta { template - inline char operator<<(Stream&, const T&); + inline No operator<<(Stream&, const T&); template struct isStreamable { - enum { value = sizeof(operator<<(meta::declval(), meta::declval())) != sizeof(char) }; + enum { value = sizeof(operator<<(meta::declval(), meta::declval())) != sizeof(No) }; }; template