#ifndef V8_BASE_SAFE_CONVERSIONS_H_
#define V8_BASE_SAFE_CONVERSIONS_H_
#include <stddef.h>
#include <cmath>
#include <limits>
#include <type_traits>
#include "src/base/safe_conversions_impl.h"
#if defined(__ARMEL__) && !defined(__native_client__)
#include "src/base/safe_conversions_arm_impl.h"
#define BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS …
#else
#define BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS …
#endif
#if !BASE_NUMERICS_DISABLE_OSTREAM_OPERATORS
#include <ostream>
#endif
namespace v8 {
namespace base {
namespace internal {
#if !BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS
template <typename Dst, typename Src>
struct SaturateFastAsmOp { … };
#endif
#undef BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS
template <typename Dst, typename Src, typename Enable = void>
struct IsValueInRangeFastOp { … };
IsValueInRangeFastOp<Dst, Src, typename std::enable_if<std::is_integral<Dst>::value && std::is_integral<Src>::value && std::is_signed<Dst>::value && std::is_signed<Src>::value && !IsTypeInRangeForNumericType<Dst, Src>::value>::type>;
IsValueInRangeFastOp<Dst, Src, typename std::enable_if<std::is_integral<Dst>::value && std::is_integral<Src>::value && !std::is_signed<Dst>::value && std::is_signed<Src>::value && !IsTypeInRangeForNumericType<Dst, Src>::value>::type>;
template <typename Dst, typename Src>
constexpr bool IsValueInRangeForNumericType(Src value) { … }
template <typename Dst, class CheckHandler = internal::CheckOnFailure,
typename Src>
constexpr Dst checked_cast(Src value) { … }
template <typename T>
struct SaturationDefaultLimits : public std::numeric_limits<T> { … };
template <typename Dst, template <typename> class S, typename Src>
constexpr Dst saturated_cast_impl(Src value, RangeCheck constraint) { … }
template <typename Dst, typename Src, typename Enable = void>
struct SaturateFastOp { … };
SaturateFastOp<Dst, Src, typename std::enable_if<std::is_integral<Src>::value && std::is_integral<Dst>::value && SaturateFastAsmOp<Dst, Src>::is_supported>::type>;
SaturateFastOp<Dst, Src, typename std::enable_if<std::is_integral<Src>::value && std::is_integral<Dst>::value && !SaturateFastAsmOp<Dst, Src>::is_supported>::type>;
template <typename Dst,
template <typename> class SaturationHandler = SaturationDefaultLimits,
typename Src>
constexpr Dst saturated_cast(Src value) { … }
template <typename Dst, typename Src>
constexpr Dst strict_cast(Src value) { … }
template <typename Dst, typename Src, class Enable = void>
struct IsNumericRangeContained { … };
IsNumericRangeContained<Dst, Src, typename std::enable_if<ArithmeticOrUnderlyingEnum<Dst>::value && ArithmeticOrUnderlyingEnum<Src>::value>::type>;
template <typename T>
class StrictNumeric { … };
template <typename T>
constexpr StrictNumeric<typename UnderlyingType<T>::type> MakeStrictNum(
const T value) { … }
#if !BASE_NUMERICS_DISABLE_OSTREAM_OPERATORS
template <typename T>
std::ostream& operator<<(std::ostream& os, const StrictNumeric<T>& value) { … }
#endif
#define BASE_NUMERIC_COMPARISON_OPERATORS(CLASS, NAME, OP) …
BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsLess, <)
BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsLessOrEqual, <=)
BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsGreater, >)
BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsGreaterOrEqual, >=)
BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsEqual, ==)
BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsNotEqual, !=)
}
as_signed;
as_unsigned;
checked_cast;
IsTypeInRangeForNumericType;
IsValueInRangeForNumericType;
IsValueNegative;
MakeStrictNum;
SafeUnsignedAbs;
saturated_cast;
strict_cast;
StrictNumeric;
SizeT;
template <typename Dst = int, typename Src,
typename = std::enable_if_t<std::is_integral<Dst>::value &&
std::is_floating_point<Src>::value>>
Dst ClampFloor(Src value) { … }
template <typename Dst = int, typename Src,
typename = std::enable_if_t<std::is_integral<Dst>::value &&
std::is_floating_point<Src>::value>>
Dst ClampCeil(Src value) { … }
template <typename Dst = int, typename Src,
typename = std::enable_if_t<std::is_integral<Dst>::value &&
std::is_floating_point<Src>::value>>
Dst ClampRound(Src value) { … }
}
}
#endif