#ifndef BOOST_UUID_DETAIL_NUMERIC_CAST_INCLUDED #define BOOST_UUID_DETAIL_NUMERIC_CAST_INCLUDED // Copyright 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #include #include #include #include #include namespace boost { namespace uuids { namespace detail { template T numeric_cast( U u ) { BOOST_UUID_STATIC_ASSERT( std::is_integral::value ); BOOST_UUID_STATIC_ASSERT( std::is_unsigned::value ); BOOST_UUID_STATIC_ASSERT( std::is_integral::value ); BOOST_UUID_STATIC_ASSERT( std::is_unsigned::value ); if( u > std::numeric_limits::max() ) { BOOST_THROW_EXCEPTION( std::range_error( "Argument to numeric_cast is out of range of destination type" ) ); } return static_cast( u ); } } // detail } // uuids } // boost #endif // #ifndef BOOST_UUID_DETAIL_NUMERIC_CAST_INCLUDED