File indexing completed on 2025-01-18 09:53:21
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_UNORDERED_DETAIL_NARROW_CAST_HPP
0010 #define BOOST_UNORDERED_DETAIL_NARROW_CAST_HPP
0011
0012 #include <boost/unordered/detail/static_assert.hpp>
0013
0014 #include <boost/config.hpp>
0015 #include <type_traits>
0016
0017 namespace boost{
0018 namespace unordered{
0019 namespace detail{
0020
0021 template<typename To,typename From>
0022 constexpr To narrow_cast(From x) noexcept
0023 {
0024 BOOST_UNORDERED_STATIC_ASSERT(std::is_integral<From>::value);
0025 BOOST_UNORDERED_STATIC_ASSERT(std::is_integral<To>::value);
0026 BOOST_UNORDERED_STATIC_ASSERT(sizeof(From)>=sizeof(To));
0027
0028 return static_cast<To>(
0029 x
0030
0031 #if defined(__MSVC_RUNTIME_CHECKS)
0032
0033
0034
0035 &static_cast<typename std::make_unsigned<To>::type>(~static_cast<To>(0))
0036 #endif
0037 );
0038 }
0039
0040 }
0041 }
0042 }
0043
0044 #endif