/* Copyright 2022 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * See https://www.boost.org/libs/unordered for library home page. */ #ifndef BOOST_UNORDERED_DETAIL_NARROW_CAST_HPP #define BOOST_UNORDERED_DETAIL_NARROW_CAST_HPP #include #include #include namespace boost{ namespace unordered{ namespace detail{ template constexpr To narrow_cast(From x) noexcept { BOOST_UNORDERED_STATIC_ASSERT(std::is_integral::value); BOOST_UNORDERED_STATIC_ASSERT(std::is_integral::value); BOOST_UNORDERED_STATIC_ASSERT(sizeof(From)>=sizeof(To)); return static_cast( x #if defined(__MSVC_RUNTIME_CHECKS) /* Avoids VS's "Run-Time Check Failure #1 - A cast to a smaller data type * has caused a loss of data." */ &static_cast::type>(~static_cast(0)) #endif ); } } /* namespace detail */ } /* namespace unordered */ } /* namespace boost */ #endif