Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / endian / detail / endian_reverse.hpp
index cb80c79..88fcf20 100644 (file)
 #include <cstddef>
 #include <cstring>
 
+#if defined(BOOST_ENDIAN_NO_INTRINSICS)
+# if defined(BOOST_NO_CXX14_CONSTEXPR)
+#  define BOOST_ENDIAN_CONSTEXPR
+# else
+#  define BOOST_ENDIAN_CONSTEXPR constexpr
+# endif
+#else
+# if defined(BOOST_ENDIAN_CONSTEXPR_INTRINSICS)
+#  define BOOST_ENDIAN_CONSTEXPR BOOST_CONSTEXPR
+# else
+#  define BOOST_ENDIAN_CONSTEXPR
+# endif
+#endif
+
 namespace boost
 {
 namespace endian
@@ -30,12 +44,12 @@ namespace detail
 //  -- intrinsic approach suggested by reviewers, and by David Stone, who provided
 //     his Boost licensed macro implementation (detail/intrinsic.hpp)
 
-inline uint8_t endian_reverse_impl( uint8_t x ) BOOST_NOEXCEPT
+inline uint8_t BOOST_CONSTEXPR endian_reverse_impl( uint8_t x ) BOOST_NOEXCEPT
 {
     return x;
 }
 
-inline uint16_t endian_reverse_impl( uint16_t x ) BOOST_NOEXCEPT
+inline uint16_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint16_t x ) BOOST_NOEXCEPT
 {
 #ifdef BOOST_ENDIAN_NO_INTRINSICS
 
@@ -48,7 +62,7 @@ inline uint16_t endian_reverse_impl( uint16_t x ) BOOST_NOEXCEPT
 #endif
 }
 
-inline uint32_t endian_reverse_impl(uint32_t x) BOOST_NOEXCEPT
+inline uint32_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint32_t x ) BOOST_NOEXCEPT
 {
 #ifdef BOOST_ENDIAN_NO_INTRINSICS
 
@@ -62,7 +76,7 @@ inline uint32_t endian_reverse_impl(uint32_t x) BOOST_NOEXCEPT
 #endif
 }
 
-inline uint64_t endian_reverse_impl(uint64_t x) BOOST_NOEXCEPT
+inline uint64_t BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint64_t x ) BOOST_NOEXCEPT
 {
 #ifdef BOOST_ENDIAN_NO_INTRINSICS
 
@@ -77,14 +91,24 @@ inline uint64_t endian_reverse_impl(uint64_t x) BOOST_NOEXCEPT
 # endif
 }
 
+#if defined(BOOST_HAS_INT128)
+
+inline uint128_type BOOST_ENDIAN_CONSTEXPR endian_reverse_impl( uint128_type x ) BOOST_NOEXCEPT
+{
+    return endian_reverse_impl( static_cast<uint64_t>( x >> 64 ) ) |
+        static_cast<uint128_type>( endian_reverse_impl( static_cast<uint64_t>( x ) ) ) << 64;
+}
+
+#endif
+
 } // namespace detail
 
 // Requires:
 //    T is non-bool integral
 
-template<class T> inline T endian_reverse( T x ) BOOST_NOEXCEPT
+template<class T> inline BOOST_CONSTEXPR T endian_reverse( T x ) BOOST_NOEXCEPT
 {
-    BOOST_STATIC_ASSERT( is_integral<T>::value && !is_same<T, bool>::value );
+    BOOST_STATIC_ASSERT( is_integral<T>::value && !(is_same<T, bool>::value) );
 
     typedef typename detail::integral_by_size< sizeof(T) >::type uintN_t;