]> git.lyx.org Git - lyx.git/blobdiff - 3rdparty/boost/boost/type_index/detail/compile_time_type_info.hpp
Update to boost 1.72
[lyx.git] / 3rdparty / boost / boost / type_index / detail / compile_time_type_info.hpp
index 7a55350b9e051ba727bf4cb397c651ef0913e8c2..0197a0170d45226281d773ed7fec8bd55056662d 100644 (file)
@@ -1,5 +1,5 @@
 //
-// Copyright (c) Antony Polukhin, 2012-2018.
+// Copyright (c) 2012-2019 Antony Polukhin.
 //
 //
 // Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -13,6 +13,7 @@
 /// \brief Contains helper macros and implementation details of boost::typeindex::ctti_type_index.
 /// Not intended for inclusion from user's code.
 
+#include <cstring>
 #include <boost/config.hpp>
 #include <boost/static_assert.hpp>
 #include <boost/type_traits/integral_constant.hpp>
 #endif
 
 /// @cond
+#if defined(__has_builtin)
+#if __has_builtin(__builtin_constant_p)
+#define BOOST_TYPE_INDEX_DETAIL_IS_CONSTANT(x) __builtin_constant_p(x)
+#endif
+#if __has_builtin(__builtin_strcmp)
+#define BOOST_TYPE_INDEX_DETAIL_BUILTIN_STRCMP(str1, str2) __builtin_strcmp(str1, str2)
+#endif
+#elif defined(__GNUC__)
+#define BOOST_TYPE_INDEX_DETAIL_IS_CONSTANT(x) __builtin_constant_p(x)
+#define BOOST_TYPE_INDEX_DETAIL_BUILTIN_STRCMP(str1, str2) __builtin_strcmp(str1, str2)
+#endif
+
 #define BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(begin_skip, end_skip, runtime_skip, runtime_skip_until)   \
     namespace boost { namespace typeindex { namespace detail {                                                  \
         BOOST_STATIC_CONSTEXPR std::size_t ctti_skip_size_at_begin  = begin_skip;                               \
 #elif defined(BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING)
 #   include <boost/preprocessor/facilities/expand.hpp>
     BOOST_PP_EXPAND( BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS BOOST_TYPE_INDEX_CTTI_USER_DEFINED_PARSING )
-#elif defined(_MSC_VER) && defined (BOOST_NO_CXX11_NOEXCEPT)
+#elif defined(_MSC_VER) && !defined(__clang__) && defined (BOOST_NO_CXX11_NOEXCEPT)
     // sizeof("const char *__cdecl boost::detail::ctti<") - 1, sizeof(">::n(void)") - 1
     BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(40, 10, false, "")
-#elif defined(_MSC_VER) && !defined (BOOST_NO_CXX11_NOEXCEPT)
+#elif defined(_MSC_VER) && !defined(__clang__) && !defined (BOOST_NO_CXX11_NOEXCEPT)
     // sizeof("const char *__cdecl boost::detail::ctti<") - 1, sizeof(">::n(void) noexcept") - 1
     BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(40, 19, false, "")
 #elif defined(__clang__) && defined(__APPLE__)
@@ -76,6 +89,9 @@
 #elif defined(__GNUC__) && defined(BOOST_NO_CXX14_CONSTEXPR)
     // sizeof("static const char* boost::detail::ctti<T>::n() [with T = ") - 1, sizeof("]") - 1
     BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(57, 1, false, "")
+#elif defined(__ghs__)
+    // sizeof("static const char *boost::detail::ctti<T>::n() [with T = ") - 1, sizeof("]") - 1
+    BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(57, 1, false, "")
 #else
     // Deafult code for other platforms... Just skip nothing!
     BOOST_TYPE_INDEX_REGISTER_CTTI_PARSING_PARAMS(0, 0, false, "")
@@ -105,6 +121,17 @@ namespace boost { namespace typeindex { namespace detail {
         );
     }
 
+#if defined(BOOST_TYPE_INDEX_DETAIL_IS_CONSTANT)
+    BOOST_CXX14_CONSTEXPR BOOST_FORCEINLINE bool is_constant_string(const char* str) BOOST_NOEXCEPT {
+        while (BOOST_TYPE_INDEX_DETAIL_IS_CONSTANT(*str)) {
+            if (*str == '\0')
+                return true;
+            ++str;
+        }
+        return false;
+    }
+#endif // defined(BOOST_TYPE_INDEX_DETAIL_IS_CONSTANT)
+
     template <unsigned int ArrayLength>
     BOOST_CXX14_CONSTEXPR inline const char* skip_begining_runtime(const char* begin, boost::false_type) BOOST_NOEXCEPT {
         return begin;
@@ -138,15 +165,27 @@ namespace boost { namespace typeindex { namespace detail {
         return last1;
     }
 
-    BOOST_CXX14_CONSTEXPR inline int constexpr_strcmp(const char *v1, const char *v2) BOOST_NOEXCEPT {
+    BOOST_CXX14_CONSTEXPR inline int constexpr_strcmp_loop(const char *v1, const char *v2) BOOST_NOEXCEPT {
         while (*v1 != '\0' && *v1 == *v2) {
             ++v1;
             ++v2;
-        };
+        }
 
         return static_cast<int>(*v1) - *v2;
     }
 
+    BOOST_CXX14_CONSTEXPR inline int constexpr_strcmp(const char *v1, const char *v2) BOOST_NOEXCEPT {
+#if !defined(BOOST_NO_CXX14_CONSTEXPR) && defined(BOOST_TYPE_INDEX_DETAIL_IS_CONSTANT) && defined(BOOST_TYPE_INDEX_DETAIL_BUILTIN_STRCMP)
+        if (boost::typeindex::detail::is_constant_string(v1) && boost::typeindex::detail::is_constant_string(v2))
+            return boost::typeindex::detail::constexpr_strcmp_loop(v1, v2);
+        return BOOST_TYPE_INDEX_DETAIL_BUILTIN_STRCMP(v1, v2);
+#elif !defined(BOOST_NO_CXX14_CONSTEXPR)
+        return boost::typeindex::detail::constexpr_strcmp_loop(v1, v2);
+#else
+        return std::strcmp(v1, v2);
+#endif
+    }
+
     template <unsigned int ArrayLength>
     BOOST_CXX14_CONSTEXPR inline const char* skip_begining_runtime(const char* begin, boost::true_type) BOOST_NOEXCEPT {
         const char* const it = constexpr_search(
@@ -257,7 +296,7 @@ struct ctti {
                     || defined(__DMC__)
         constexpr unsigned int size = sizeof(__PRETTY_FUNCTION__);
     #else
-        boost::typeindex::detail::failed_to_get_function_name();
+        boost::typeindex::detail::failed_to_get_function_name<T>();
     #endif
 
         boost::typeindex::detail::assert_compile_time_legths<
@@ -284,10 +323,11 @@ struct ctti {
                 || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) \
                 || (defined(__ICC) && (__ICC >= 600)) \
                 || defined(__ghs__) \
-                || defined(__DMC__)
+                || defined(__DMC__) \
+                || defined(__clang__)
         return boost::typeindex::detail::skip_begining< sizeof(__PRETTY_FUNCTION__) >(__PRETTY_FUNCTION__);
     #else
-        boost::typeindex::detail::failed_to_get_function_name();
+        boost::typeindex::detail::failed_to_get_function_name<T>();
         return "";
     #endif
     }