#ifndef PARTITION_ALLOC_PARTITION_ALLOC_BASE_NUMERICS_SAFE_CONVERSIONS_H_
#define PARTITION_ALLOC_PARTITION_ALLOC_BASE_NUMERICS_SAFE_CONVERSIONS_H_
#include <cmath>
#include <cstddef>
#include <limits>
#include <type_traits>
#include "partition_alloc/partition_alloc_base/numerics/safe_conversions_impl.h"
#if defined(__ARMEL__) && !defined(__native_client__)
#include "partition_alloc/partition_alloc_base/numerics/safe_conversions_arm_impl.h"
#define PA_BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS …
#else
#define PA_BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS …
#endif
#if !PA_BASE_NUMERICS_DISABLE_OSTREAM_OPERATORS
#include <ostream>
#endif
namespace partition_alloc::internal::base {
namespace internal {
#if !PA_BASE_HAS_OPTIMIZED_SAFE_CONVERSIONS
template <typename Dst, typename Src>
struct SaturateFastAsmOp { … };
#endif
#undef PA_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_v<Dst> && std::is_integral_v<Src> && std::is_signed_v<Dst> && std::is_signed_v<Src> && !IsTypeInRangeForNumericType<Dst, Src>::value>::type>;
IsValueInRangeFastOp<Dst, Src, typename std::enable_if<std::is_integral_v<Dst> && std::is_integral_v<Src> && !std::is_signed_v<Dst> && std::is_signed_v<Src> && !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_v<Src> && std::is_integral_v<Dst> && SaturateFastAsmOp<Dst, Src>::is_supported>::type>;
SaturateFastOp<Dst, Src, typename std::enable_if<std::is_integral_v<Src> && std::is_integral_v<Dst> && !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) { … }
#define PA_BASE_NUMERIC_COMPARISON_OPERATORS(CLASS, NAME, OP) …
PA_BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsLess, <)
PA_BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsLessOrEqual, <=)
PA_BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsGreater, >)
PA_BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsGreaterOrEqual, >=)
PA_BASE_NUMERIC_COMPARISON_OPERATORS(Strict, IsEqual, ==)
PA_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_v<Dst> &&
std::is_floating_point_v<Src>>>
Dst ClampFloor(Src value) { … }
template <typename Dst = int,
typename Src,
typename = std::enable_if_t<std::is_integral_v<Dst> &&
std::is_floating_point_v<Src>>>
Dst ClampCeil(Src value) { … }
template <typename Dst = int,
typename Src,
typename = std::enable_if_t<std::is_integral_v<Dst> &&
std::is_floating_point_v<Src>>>
Dst ClampRound(Src value) { … }
}
#endif