Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/uuid/detail/numeric_cast.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #ifndef BOOST_UUID_DETAIL_NUMERIC_CAST_INCLUDED
0002 #define BOOST_UUID_DETAIL_NUMERIC_CAST_INCLUDED
0003 
0004 // Copyright 2024 Peter Dimov
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // https://www.boost.org/LICENSE_1_0.txt
0007 
0008 #include <boost/uuid/detail/static_assert.hpp>
0009 #include <boost/throw_exception.hpp>
0010 #include <stdexcept>
0011 #include <limits>
0012 #include <type_traits>
0013 
0014 namespace boost {
0015 namespace uuids {
0016 namespace detail {
0017 
0018 template<class T, class U> T numeric_cast( U u )
0019 {
0020     BOOST_UUID_STATIC_ASSERT( std::is_integral<T>::value );
0021     BOOST_UUID_STATIC_ASSERT( std::is_unsigned<T>::value );
0022 
0023     BOOST_UUID_STATIC_ASSERT( std::is_integral<U>::value );
0024     BOOST_UUID_STATIC_ASSERT( std::is_unsigned<U>::value );
0025 
0026     if( u > std::numeric_limits<T>::max() )
0027     {
0028         BOOST_THROW_EXCEPTION( std::range_error( "Argument to numeric_cast is out of range of destination type" ) );
0029     }
0030 
0031     return static_cast<T>( u );
0032 }
0033 
0034 } // detail
0035 } // uuids
0036 } // boost
0037 
0038 #endif // #ifndef BOOST_UUID_DETAIL_NUMERIC_CAST_INCLUDED