From e1f48ad35ad1bbdbc3ded1ff537e362011a6c876 Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Thu, 23 Aug 2018 09:48:03 -0700 Subject: Updated preprocessor check for template aliases. (#4888) --- include/flatbuffers/stl_emulation.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/include/flatbuffers/stl_emulation.h b/include/flatbuffers/stl_emulation.h index 7e7e978a..ff537cd4 100644 --- a/include/flatbuffers/stl_emulation.h +++ b/include/flatbuffers/stl_emulation.h @@ -33,6 +33,16 @@ #include #endif // defined(FLATBUFFERS_CPP98_STL) +// Check if we can use template aliases +// Not possible if Microsoft Compiler before 2012 +// Possible is the language feature __cpp_alias_templates is defined well +// Or possible if the C++ std is C+11 or newer +#if !(defined(_MSC_VER) && _MSC_VER <= 1700 /* MSVC2012 */) \ + && ((defined(__cpp_alias_templates) && __cpp_alias_templates >= 200704) \ + || (defined(__cplusplus) && __cplusplus >= 201103L)) + #define FLATBUFFERS_TEMPLATES_ALIASES +#endif + // This header provides backwards compatibility for C++98 STLs like stlport. namespace flatbuffers { @@ -69,13 +79,13 @@ inline void vector_emplace_back(std::vector *vector, V &&data) { } #ifndef FLATBUFFERS_CPP98_STL - #if !(defined(_MSC_VER) && _MSC_VER <= 1700 /* MSVC2012 */) + #if defined(FLATBUFFERS_TEMPLATES_ALIASES) template using numeric_limits = std::numeric_limits; #else template class numeric_limits : public std::numeric_limits {}; - #endif // !(defined(_MSC_VER) && _MSC_VER <= 1700 /* MSVC2012 */) + #endif // defined(FLATBUFFERS_TEMPLATES_ALIASES) #else template class numeric_limits : public std::numeric_limits {}; @@ -98,7 +108,7 @@ inline void vector_emplace_back(std::vector *vector, V &&data) { }; #endif // FLATBUFFERS_CPP98_STL -#if !(defined(_MSC_VER) && _MSC_VER <= 1700 /* MSVC2012 */) +#if defined(FLATBUFFERS_TEMPLATES_ALIASES) #ifndef FLATBUFFERS_CPP98_STL template using is_scalar = std::is_scalar; template using is_same = std::is_same; @@ -119,10 +129,10 @@ inline void vector_emplace_back(std::vector *vector, V &&data) { template struct is_floating_point : public std::is_floating_point {}; template struct is_unsigned : public std::is_unsigned {}; -#endif // !(defined(_MSC_VER) && _MSC_VER <= 1700 /* MSVC2012 */) +#endif // defined(FLATBUFFERS_TEMPLATES_ALIASES) #ifndef FLATBUFFERS_CPP98_STL - #if !(defined(_MSC_VER) && _MSC_VER <= 1700 /* MSVC2012 */) + #if defined(FLATBUFFERS_TEMPLATES_ALIASES) template using unique_ptr = std::unique_ptr; #else // MSVC 2010 doesn't support C++11 aliases. @@ -148,7 +158,7 @@ inline void vector_emplace_back(std::vector *vector, V &&data) { return std::unique_ptr::operator=(p); } }; - #endif // !(defined(_MSC_VER) && _MSC_VER <= 1700 /* MSVC2012 */) + #endif // defined(FLATBUFFERS_TEMPLATES_ALIASES) #else // Very limited implementation of unique_ptr. // This is provided simply to allow the C++ code generated from the default -- cgit v1.2.3