From e416edcbe695ed1fe758d7e4b755da626db4bb1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sun, 24 May 2026 02:04:11 +0200 Subject: [PATCH] Add BOOST_CONTAINER_HAS_BUILTIN and BOOST_CONTAINER_ASSUME --- include/boost/container/detail/workaround.hpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/boost/container/detail/workaround.hpp b/include/boost/container/detail/workaround.hpp index f19c85b..d586d2a 100644 --- a/include/boost/container/detail/workaround.hpp +++ b/include/boost/container/detail/workaround.hpp @@ -268,4 +268,29 @@ namespace boost { #define BOOST_CONTAINER_UNROLL(n) #endif +#ifdef __has_builtin +#define BOOST_CONTAINER_HAS_BUILTIN(x) __has_builtin(x) +#else +#define BOOST_CONTAINER_HAS_BUILTIN(x) 0 +#endif + +#if !defined(NDEBUG) +#define BOOST_CONTAINER_ASSUME(cond) BOOST_ASSERT(cond) +#elif BOOST_CONTAINER_HAS_BUILTIN(__builtin_assume) +#define BOOST_CONTAINER_ASSUME(cond) __builtin_assume(cond) +#elif defined(__GNUC__) || \ + BOOST_CONTAINER_HAS_BUILTIN(__builtin_unreachable) +#define BOOST_CONTAINER_ASSUME(cond) \ + do{ \ + if(!(cond)) __builtin_unreachable(); \ + } while(0) +#elif defined(_MSC_VER) +#define BOOST_CONTAINER_ASSUME(cond) __assume(cond) +#else +#define BOOST_CONTAINER_ASSUME(cond) \ + do{ \ + static_cast(false && (cond)); \ + } while(0) +#endif + #endif //#ifndef BOOST_CONTAINER_DETAIL_WORKAROUND_HPP