5#ifndef BASE_NUMERICS_CHECKED_MATH_H_
6#define BASE_NUMERICS_CHECKED_MATH_H_
20 "CheckedNumeric<T>: T must be a numeric type.");
28 template <
typename Src>
32 template <
typename Src>
37 template <
typename Src>
45 template <
typename Src>
48 : state_(static_cast<Src>(
value)) {}
53 template <
typename Dst = T>
55 return state_.is_valid() &&
56 IsValueInRangeForNumericType<Dst>(state_.value());
62 template <
typename Dst>
63#if defined(__clang__) || defined(__GNUC__)
65#elif defined(_MSC_VER)
71 ? ((*
result =
static_cast<Dst
>(state_.value())),
true)
83 template <
typename Dst = T,
class CheckHandler = CheckOnFailure>
86 ?
static_cast<Dst
>(state_.value())
87 : CheckHandler::template HandleFailure<Dst>();
96 template <
typename Dst = T,
typename Src>
99 ?
static_cast<Dst
>(state_.value())
100 : checked_cast<Dst>(default_value);
106 template <
typename Dst>
114 template <
typename U>
118 template <
typename Src>
120 template <
typename Src>
122 template <
typename Src>
124 template <
typename Src>
126 template <
typename Src>
128 template <
typename Src>
130 template <
typename Src>
132 template <
typename Src>
134 template <
typename Src>
136 template <
typename Src>
150 std::numeric_limits<T>::lowest()))
151 : FastRuntimeNegate();
163 template <
typename U>
171 static_cast<result_type
>(
178 template <
typename U>
186 static_cast<result_type
>(
226 template <
template <
typename,
typename,
typename>
class M,
239 template <
template <
typename,
typename,
typename>
class M,
typename R>
258 template <
typename Src>
264 template <
typename Src>
266 static constexpr bool is_valid(Src) {
return true; }
270 template <
typename Src>
272 static constexpr bool is_valid(
const CheckedNumeric<Src> v) {
275 static constexpr Src
value(
const CheckedNumeric<Src> v) {
276 return v.state_.value();
280 template <
typename Src>
281 struct Wrapper<StrictNumeric<Src>> {
282 static constexpr bool is_valid(
const StrictNumeric<Src>) {
return true; }
283 static constexpr Src
value(
const StrictNumeric<Src> v) {
284 return static_cast<Src
>(v);
290template <
typename Dst,
typename Src>
292 return value.template IsValid<Dst>();
295template <
typename Dst,
typename Src>
298 return value.template ValueOrDie<Dst>();
301template <
typename Dst,
typename Src,
typename Default>
304 const Default default_value) {
305 return value.template ValueOrDefault<Dst>(default_value);
317template <
template <
typename,
typename,
typename>
class M,
329template <
template <
typename,
typename,
typename>
class M,
335 return CheckMathOp<M>(CheckMathOp<M>(lhs, rhs),
args...);
354template <typename
L, typename
R>
356 uintptr_t
result = CheckAdd(
reinterpret_cast<uintptr_t
>(lhs),
357 CheckMul(
sizeof(
L),
static_cast<R>(rhs)))
358 .template ValueOrDie<uintptr_t>();
359 return reinterpret_cast<L*
>(
result);
362template <
typename L,
typename R>
364 uintptr_t
result = CheckSub(
reinterpret_cast<uintptr_t
>(lhs),
365 CheckMul(
sizeof(
L),
static_cast<R>(rhs)))
366 .template ValueOrDie<uintptr_t>();
367 return reinterpret_cast<L*
>(
result);
372using internal::CheckAdd;
373using internal::CheckAnd;
374using internal::CheckDiv;
375using internal::CheckedNumeric;
376using internal::CheckLsh;
377using internal::CheckMax;
378using internal::CheckMin;
379using internal::CheckMod;
380using internal::CheckMul;
381using internal::CheckOr;
382using internal::CheckRsh;
383using internal::CheckSub;
384using internal::CheckXor;
static bool is_valid(SkISize dim)
constexpr CheckedNumeric(StrictNumeric< Src > value)
constexpr CheckedNumeric & operator*=(const Src rhs)
friend class CheckedNumeric
constexpr CheckedNumeric(const CheckedNumeric< Src > &rhs)
constexpr CheckedNumeric & operator&=(const Src rhs)
constexpr StrictNumeric< Dst > ValueOrDie() const
static constexpr CheckedNumeric MathOp(const L lhs, const R rhs)
constexpr CheckedNumeric operator++(int)
constexpr StrictNumeric< Dst > ValueOrDefault(const Src default_value) const
constexpr CheckedNumeric< typename MathWrapper< CheckedMaxOp, T, U >::type > Max(const U rhs) const
constexpr bool AssignIfValid(Dst *result) const
constexpr CheckedNumeric & operator|=(const Src rhs)
constexpr CheckedNumeric operator-() const
constexpr CheckedNumeric & operator--()
constexpr CheckedNumeric operator--(int)
constexpr CheckedNumeric & operator/=(const Src rhs)
constexpr CheckedNumeric & operator-=(const Src rhs)
constexpr CheckedNumeric< typename UnderlyingType< Dst >::type > Cast() const
constexpr CheckedNumeric & MathOp(const R rhs)
constexpr bool IsValid() const
constexpr CheckedNumeric()=default
constexpr CheckedNumeric(Src value)
constexpr CheckedNumeric & operator<<=(const Src rhs)
constexpr CheckedNumeric< typename UnsignedOrFloatForSize< T >::type > UnsignedAbs() const
constexpr CheckedNumeric & operator>>=(const Src rhs)
friend U GetNumericValueForTest(const CheckedNumeric< U > &src)
constexpr CheckedNumeric & operator^=(const Src rhs)
constexpr CheckedNumeric Abs() const
constexpr CheckedNumeric & operator+=(const Src rhs)
constexpr CheckedNumeric operator~() const
constexpr CheckedNumeric & operator++()
constexpr CheckedNumeric & operator%=(const Src rhs)
constexpr CheckedNumeric< typename MathWrapper< CheckedMinOp, T, U >::type > Min(const U rhs) const
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
__attribute__((visibility("default"))) int RunBenchmarks(int argc
constexpr T NegateWrapper(T value)
constexpr bool IsValueNegative(T value)
constexpr CheckedNumeric< typename MathWrapper< M, L, R >::type > CheckMathOp(const L lhs, const R rhs)
constexpr std::make_unsigned< T >::type SafeUnsignedAbs(T value)
constexpr bool IsValidForType(const CheckedNumeric< Src > value)
constexpr CheckedNumeric< typename UnderlyingType< T >::type > MakeCheckedNum(const T value)
constexpr StrictNumeric< Dst > ValueOrDefaultForType(const CheckedNumeric< Src > value, const Default default_value)
L * operator-(L *lhs, const StrictNumeric< R > rhs)
constexpr StrictNumeric< Dst > ValueOrDieForType(const CheckedNumeric< Src > value)
constexpr std::make_unsigned< T >::type InvertWrapper(T value)
constexpr bool MustTreatAsConstexpr(const T v)
static CompileType * ResultType(Definition *call)
static constexpr Color Min(Color c, float threshold)
#define BASE_NUMERICS_LIKELY(x)
#define BASE_NUMERIC_ARITHMETIC_OPERATORS(CLASS, CL_ABBR, OP_NAME, OP, CMP_OP)
#define BASE_NUMERIC_ARITHMETIC_VARIADIC(CLASS, CL_ABBR, OP_NAME)
typename math::result_type type
M< typename UnderlyingType< L >::type, typename UnderlyingType< R >::type, void > math
typename ArithmeticOrUnderlyingEnum< T >::type type