Alien-boost-mini
view release on metacpan or search on metacpan
include/boost/numeric/conversion/detail/old_numeric_cast.hpp view on Meta::CPAN
};
# endif
} // namespace detail
// less_than_type_min -
// x_is_signed should be numeric_limits<X>::is_signed
// y_is_signed should be numeric_limits<Y>::is_signed
// y_min should be numeric_limits<Y>::min()
//
// check(x, y_min) returns true iff x < y_min without invoking comparisons
// between signed and unsigned values.
//
// "poor man's partial specialization" is in use here.
template <bool x_is_signed, bool y_is_signed>
struct less_than_type_min
{
template <class X, class Y>
static bool check(X x, Y y_min)
{ return x < y_min; }
};
template <>
struct less_than_type_min<false, true>
{
template <class X, class Y>
static bool check(X, Y)
{ return false; }
};
template <>
struct less_than_type_min<true, false>
{
template <class X, class Y>
static bool check(X x, Y)
{ return x < 0; }
};
// greater_than_type_max -
// same_sign should be:
// numeric_limits<X>::is_signed == numeric_limits<Y>::is_signed
// y_max should be numeric_limits<Y>::max()
//
// check(x, y_max) returns true iff x > y_max without invoking comparisons
// between signed and unsigned values.
//
// "poor man's partial specialization" is in use here.
template <bool same_sign, bool x_is_signed>
struct greater_than_type_max;
template<>
struct greater_than_type_max<true, true>
{
template <class X, class Y>
static inline bool check(X x, Y y_max)
{ return x > y_max; }
};
template <>
struct greater_than_type_max<false, true>
{
// What does the standard say about this? I think it's right, and it
// will work with every compiler I know of.
template <class X, class Y>
static inline bool check(X x, Y)
{ return x >= 0 && static_cast<X>(static_cast<Y>(x)) != x; }
};
template<>
struct greater_than_type_max<true, false>
{
template <class X, class Y>
static inline bool check(X x, Y y_max)
{ return x > y_max; }
};
template <>
struct greater_than_type_max<false, false>
{
// What does the standard say about this? I think it's right, and it
// will work with every compiler I know of.
template <class X, class Y>
static inline bool check(X x, Y)
{ return static_cast<X>(static_cast<Y>(x)) != x; }
};
#else // use #pragma hacks if available
namespace detail
{
# if BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4018)
# pragma warning(disable : 4146)
#elif defined(__BORLANDC__)
# pragma option push -w-8041
# endif
// Move to namespace boost in utility.hpp?
template <class T>
struct fixed_numeric_limits : public std::numeric_limits<T>
{
static inline T min BOOST_PREVENT_MACRO_SUBSTITUTION ()
{
return std::numeric_limits<T>::is_signed && (std::numeric_limits<T>::min)() >= 0
? T(-(std::numeric_limits<T>::max)()) : (std::numeric_limits<T>::min)();
}
};
# if BOOST_MSVC
# pragma warning(pop)
#elif defined(__BORLANDC__)
# pragma option pop
# endif
} // namespace detail
#endif
template<typename Target, typename Source>
inline Target numeric_cast(Source arg)
{
// typedefs abbreviating respective trait classes
typedef detail::fixed_numeric_limits<Source> arg_traits;
typedef detail::fixed_numeric_limits<Target> result_traits;
#if defined(BOOST_STRICT_CONFIG) \
|| (!defined(__HP_aCC) || __HP_aCC > 33900) \
&& (!defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) \
|| defined(BOOST_SGI_CPP_LIMITS))
// typedefs that act as compile time assertions
// (to be replaced by boost compile time assertions
// as and when they become available and are stable)
typedef bool argument_must_be_numeric[arg_traits::is_specialized];
typedef bool result_must_be_numeric[result_traits::is_specialized];
const bool arg_is_signed = arg_traits::is_signed;
const bool result_is_signed = result_traits::is_signed;
const bool same_sign = arg_is_signed == result_is_signed;
if (less_than_type_min<arg_is_signed, result_is_signed>::check(arg, (result_traits::min)())
( run in 0.543 second using v1.01-cache-2.11-cpan-483215c6ad5 )