Flutter Engine
The Flutter Engine
Classes | Enumerations | Functions
base::internal Namespace Reference

Classes

struct  ArithmeticOrUnderlyingEnum
 
struct  ArithmeticOrUnderlyingEnum< T, false >
 
struct  ArithmeticOrUnderlyingEnum< T, true >
 
struct  BigEnoughPromotion
 
struct  BigEnoughPromotion< Lhs, Rhs, false, false >
 
struct  BigEnoughPromotion< Lhs, Rhs, is_intmax_type, true >
 
struct  BigEnoughPromotion< Lhs, Rhs, true, false >
 
struct  CheckedAddFastOp
 
struct  CheckedAddOp
 
struct  CheckedAddOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  CheckedAndOp
 
struct  CheckedAndOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  CheckedDivOp
 
struct  CheckedDivOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  CheckedLshOp
 
struct  CheckedLshOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  CheckedMaxOp
 
struct  CheckedMaxOp< T, U, typename std::enable_if< std::is_arithmetic< T >::value &&std::is_arithmetic< U >::value >::type >
 
struct  CheckedMinOp
 
struct  CheckedMinOp< T, U, typename std::enable_if< std::is_arithmetic< T >::value &&std::is_arithmetic< U >::value >::type >
 
struct  CheckedModOp
 
struct  CheckedModOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  CheckedMulFastAsmOp
 
struct  CheckedMulFastOp
 
struct  CheckedMulOp
 
struct  CheckedMulOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
class  CheckedNumeric
 
class  CheckedNumericState
 
class  CheckedNumericState< T, NUMERIC_FLOATING >
 
class  CheckedNumericState< T, NUMERIC_INTEGER >
 
struct  CheckedOrOp
 
struct  CheckedOrOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  CheckedRshOp
 
struct  CheckedRshOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  CheckedSubFastOp
 
struct  CheckedSubOp
 
struct  CheckedSubOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  CheckedXorOp
 
struct  CheckedXorOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  CheckOnFailure
 
struct  ClampedAddFastAsmOp
 
struct  ClampedAddFastOp
 
struct  ClampedAddOp
 
struct  ClampedAddOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  ClampedAndOp
 
struct  ClampedAndOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  ClampedDivOp
 
struct  ClampedDivOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  ClampedLshOp
 
struct  ClampedLshOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  ClampedMaxOp
 
struct  ClampedMaxOp< T, U, typename std::enable_if< std::is_arithmetic< T >::value &&std::is_arithmetic< U >::value >::type >
 
struct  ClampedMinOp
 
struct  ClampedMinOp< T, U, typename std::enable_if< std::is_arithmetic< T >::value &&std::is_arithmetic< U >::value >::type >
 
struct  ClampedModOp
 
struct  ClampedModOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  ClampedMulFastAsmOp
 
struct  ClampedMulFastOp
 
struct  ClampedMulOp
 
struct  ClampedMulOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  ClampedNegFastOp
 
class  ClampedNumeric
 
struct  ClampedOrOp
 
struct  ClampedOrOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  ClampedRshOp
 
struct  ClampedRshOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  ClampedSubFastAsmOp
 
struct  ClampedSubFastOp
 
struct  ClampedSubOp
 
struct  ClampedSubOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  ClampedXorOp
 
struct  ClampedXorOp< T, U, typename std::enable_if< std::is_integral< T >::value &&std::is_integral< U >::value >::type >
 
struct  DstRangeRelationToSrcRangeImpl
 
struct  DstRangeRelationToSrcRangeImpl< Dst, Src, Bounds, DstSign, SrcSign, NUMERIC_RANGE_CONTAINED >
 
struct  DstRangeRelationToSrcRangeImpl< Dst, Src, Bounds, INTEGER_REPRESENTATION_SIGNED, INTEGER_REPRESENTATION_SIGNED, NUMERIC_RANGE_NOT_CONTAINED >
 
struct  DstRangeRelationToSrcRangeImpl< Dst, Src, Bounds, INTEGER_REPRESENTATION_SIGNED, INTEGER_REPRESENTATION_UNSIGNED, NUMERIC_RANGE_NOT_CONTAINED >
 
struct  DstRangeRelationToSrcRangeImpl< Dst, Src, Bounds, INTEGER_REPRESENTATION_UNSIGNED, INTEGER_REPRESENTATION_SIGNED, NUMERIC_RANGE_NOT_CONTAINED >
 
struct  DstRangeRelationToSrcRangeImpl< Dst, Src, Bounds, INTEGER_REPRESENTATION_UNSIGNED, INTEGER_REPRESENTATION_UNSIGNED, NUMERIC_RANGE_NOT_CONTAINED >
 
struct  FastIntegerArithmeticPromotion
 
struct  FastIntegerArithmeticPromotion< Lhs, Rhs, false >
 
struct  FastIntegerArithmeticPromotion< Lhs, Rhs, true >
 
struct  GetNumericRepresentation
 
struct  IntegerBitsPlusSign
 
struct  IntegerForDigitsAndSign
 
struct  IsCheckedOp
 
struct  IsClampedOp
 
struct  IsEqual
 
struct  IsGreater
 
struct  IsGreaterOrEqual
 
struct  IsIntegerArithmeticSafe
 
struct  IsLess
 
struct  IsLessOrEqual
 
struct  IsNotEqual
 
struct  IsNumericRangeContained
 
struct  IsNumericRangeContained< Dst, Src, typename std::enable_if< ArithmeticOrUnderlyingEnum< Dst >::value &&ArithmeticOrUnderlyingEnum< Src >::value >::type >
 
struct  IsStrictOp
 
struct  IsTypeInRangeForNumericType
 
struct  IsValueInRangeFastOp
 
struct  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 >
 
struct  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 >
 
struct  LowestValuePromotion
 
struct  LowestValuePromotion< Lhs, Rhs, LEFT_PROMOTION >
 
struct  LowestValuePromotion< Lhs, Rhs, RIGHT_PROMOTION >
 
struct  MathWrapper
 
struct  MaxExponent
 
struct  MaxExponentPromotion
 
struct  MaxExponentPromotion< Lhs, Rhs, LEFT_PROMOTION >
 
struct  MaxExponentPromotion< Lhs, Rhs, RIGHT_PROMOTION >
 
struct  NarrowingRange
 
struct  PositionOfSignBit
 
class  RangeCheck
 
struct  ResultType
 
struct  ResultType< M, L, R >
 
struct  SaturateFastAsmOp
 
struct  SaturateFastOp
 
struct  SaturateFastOp< Dst, Src, typename std::enable_if< std::is_integral< Src >::value &&std::is_integral< Dst >::value &&!SaturateFastAsmOp< Dst, Src >::is_supported >::type >
 
struct  SaturateFastOp< Dst, Src, typename std::enable_if< std::is_integral< Src >::value &&std::is_integral< Dst >::value &&SaturateFastAsmOp< Dst, Src >::is_supported >::type >
 
struct  SaturationDefaultLimits
 
struct  StaticDstRangeRelationToSrcRange
 
struct  StaticDstRangeRelationToSrcRange< Dst, Src, INTEGER_REPRESENTATION_SIGNED, INTEGER_REPRESENTATION_UNSIGNED >
 
struct  StaticDstRangeRelationToSrcRange< Dst, Src, INTEGER_REPRESENTATION_UNSIGNED, INTEGER_REPRESENTATION_SIGNED >
 
struct  StaticDstRangeRelationToSrcRange< Dst, Src, Sign, Sign >
 
class  StrictNumeric
 
struct  TwiceWiderInteger
 
struct  UnderlyingType
 
struct  UnderlyingType< CheckedNumeric< T > >
 
struct  UnderlyingType< ClampedNumeric< T > >
 
struct  UnderlyingType< StrictNumeric< T > >
 
struct  UnsignedOrFloatForSize
 
struct  UnsignedOrFloatForSize< Numeric, false, true >
 
struct  UnsignedOrFloatForSize< Numeric, true, false >
 

Enumerations

enum  NumericRepresentation { NUMERIC_INTEGER , NUMERIC_FLOATING , NUMERIC_UNKNOWN }
 
enum  IntegerRepresentation { INTEGER_REPRESENTATION_UNSIGNED , INTEGER_REPRESENTATION_SIGNED }
 
enum  NumericRangeRepresentation { NUMERIC_RANGE_NOT_CONTAINED , NUMERIC_RANGE_CONTAINED }
 
enum  ArithmeticPromotionCategory { LEFT_PROMOTION , RIGHT_PROMOTION }
 

Functions

template<typename Dst , typename Src >
constexpr bool IsValidForType (const CheckedNumeric< Src > value)
 
template<typename Dst , typename Src >
constexpr StrictNumeric< Dst > ValueOrDieForType (const CheckedNumeric< Src > value)
 
template<typename Dst , typename Src , typename Default >
constexpr StrictNumeric< Dst > ValueOrDefaultForType (const CheckedNumeric< Src > value, const Default default_value)
 
template<typename T >
constexpr CheckedNumeric< typename UnderlyingType< T >::typeMakeCheckedNum (const T value)
 
template<template< typename, typename, typename > class M, typename L , typename R >
constexpr CheckedNumeric< typename MathWrapper< M, L, R >::typeCheckMathOp (const L lhs, const R rhs)
 
template<template< typename, typename, typename > class M, typename L , typename R , typename... Args>
constexpr CheckedNumeric< typename ResultType< M, L, R, Args... >::typeCheckMathOp (const L lhs, const R rhs, const Args... args)
 
template<typename L , typename R >
L * operator+ (L *lhs, const StrictNumeric< R > rhs)
 
template<typename L , typename R >
L * operator- (L *lhs, const StrictNumeric< R > rhs)
 
template<typename T >
constexpr bool CheckedAddImpl (T x, T y, T *result)
 
template<typename T >
constexpr bool CheckedSubImpl (T x, T y, T *result)
 
template<typename T >
constexpr bool CheckedMulImpl (T x, T y, T *result)
 
template<typename T >
constexpr ClampedNumeric< typename UnderlyingType< T >::typeMakeClampedNum (const T value)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, const ClampedNumeric< T > &value)
 
template<template< typename, typename, typename > class M, typename L , typename R >
constexpr ClampedNumeric< typename MathWrapper< M, L, R >::typeClampMathOp (const L lhs, const R rhs)
 
template<template< typename, typename, typename > class M, typename L , typename R , typename... Args>
constexpr ClampedNumeric< typename ResultType< M, L, R, Args... >::typeClampMathOp (const L lhs, const R rhs, const Args... args)
 
template<typename T , typename std::enable_if< std::is_integral< T >::value &&std::is_signed< T >::value >::type * = nullptr>
constexpr T SaturatedNegWrapper (T value)
 
template<typename T , typename std::enable_if< std::is_integral< T >::value >::type * = nullptr>
constexpr T SaturatedAbsWrapper (T value)
 
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 Dst , template< typename > class S, typename Src >
constexpr Dst saturated_cast_impl (Src value, RangeCheck constraint)
 
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 T >
constexpr StrictNumeric< typename UnderlyingType< T >::typeMakeStrictNum (const T value)
 
template<typename T >
std::ostream & operator<< (std::ostream &os, const StrictNumeric< T > &value)
 
template<typename T , typename std::enable_if< std::is_signed< T >::value >::type * = nullptr>
constexpr bool IsValueNegative (T value)
 
template<typename T >
constexpr std::make_signed< T >::type ConditionalNegate (T x, bool is_negative)
 
template<typename T >
constexpr std::make_unsigned< T >::type SafeUnsignedAbs (T value)
 
constexpr bool CanDetectCompileTimeConstant ()
 
template<typename T >
constexpr bool IsCompileTimeConstant (const T)
 
template<typename T >
constexpr bool MustTreatAsConstexpr (const T v)
 
template<typename Dst , template< typename > class Bounds = std::numeric_limits, typename Src >
constexpr RangeCheck DstRangeRelationToSrcRange (Src value)
 
 INTEGER_FOR_DIGITS_AND_SIGN (int8_t)
 
 INTEGER_FOR_DIGITS_AND_SIGN (uint8_t)
 
 INTEGER_FOR_DIGITS_AND_SIGN (int16_t)
 
 INTEGER_FOR_DIGITS_AND_SIGN (uint16_t)
 
 INTEGER_FOR_DIGITS_AND_SIGN (int32_t)
 
 INTEGER_FOR_DIGITS_AND_SIGN (uint32_t)
 
 INTEGER_FOR_DIGITS_AND_SIGN (int64_t)
 
 INTEGER_FOR_DIGITS_AND_SIGN (uint64_t)
 
template<typename Src >
constexpr std::make_signed< typenamebase::internal::UnderlyingType< Src >::type >::type as_signed (const Src value)
 
template<typename Src >
constexpr std::make_unsigned< typenamebase::internal::UnderlyingType< Src >::type >::type as_unsigned (const Src value)
 
template<typename L , typename R >
constexpr bool IsLessImpl (const L lhs, const R rhs, const RangeCheck l_range, const RangeCheck r_range)
 
template<typename L , typename R >
constexpr bool IsLessOrEqualImpl (const L lhs, const R rhs, const RangeCheck l_range, const RangeCheck r_range)
 
template<typename L , typename R >
constexpr bool IsGreaterImpl (const L lhs, const R rhs, const RangeCheck l_range, const RangeCheck r_range)
 
template<typename L , typename R >
constexpr bool IsGreaterOrEqualImpl (const L lhs, const R rhs, const RangeCheck l_range, const RangeCheck r_range)
 
template<template< typename, typename > class C, typename L , typename R >
constexpr bool SafeCompare (const L lhs, const R rhs)
 
template<typename Dst , typename Src >
constexpr bool IsMaxInRangeForNumericType ()
 
template<typename Dst , typename Src >
constexpr bool IsMinInRangeForNumericType ()
 
template<typename Dst , typename Src >
constexpr Dst CommonMax ()
 
template<typename Dst , typename Src >
constexpr Dst CommonMin ()
 
template<typename Dst , typename Src = Dst>
constexpr Dst CommonMaxOrMin (bool is_min)
 
template<typename T , typename std::enable_if< std::is_integral< T >::value >::type * = nullptr>
constexpr T NegateWrapper (T value)
 
template<typename T , typename std::enable_if< std::is_integral< T >::value >::type * = nullptr>
constexpr std::make_unsigned< T >::type InvertWrapper (T value)
 
template<typename T , typename std::enable_if< std::is_integral< T >::value >::type * = nullptr>
constexpr T AbsWrapper (T value)
 

Enumeration Type Documentation

◆ ArithmeticPromotionCategory

Enumerator
LEFT_PROMOTION 
RIGHT_PROMOTION 

Definition at line 443 of file safe_conversions_impl.h.

443 {
444 LEFT_PROMOTION, // Use the type of the left-hand argument.
445 RIGHT_PROMOTION // Use the type of the right-hand argument.
446};

◆ IntegerRepresentation

Enumerator
INTEGER_REPRESENTATION_UNSIGNED 
INTEGER_REPRESENTATION_SIGNED 

Definition at line 129 of file safe_conversions_impl.h.

◆ NumericRangeRepresentation

Enumerator
NUMERIC_RANGE_NOT_CONTAINED 
NUMERIC_RANGE_CONTAINED 

Definition at line 139 of file safe_conversions_impl.h.

◆ NumericRepresentation

Enumerator
NUMERIC_INTEGER 
NUMERIC_FLOATING 
NUMERIC_UNKNOWN 

Definition at line 455 of file checked_math_impl.h.

Function Documentation

◆ AbsWrapper()

template<typename T , typename std::enable_if< std::is_integral< T >::value >::type * = nullptr>
constexpr T base::internal::AbsWrapper ( T  value)
constexpr

Definition at line 159 of file safe_math_shared_impl.h.

159 {
160 return static_cast<T>(SafeUnsignedAbs(value));
161}
uint8_t value
constexpr std::make_unsigned< T >::type SafeUnsignedAbs(T value)
#define T
Definition: precompiler.cc:65

◆ as_signed()

template<typename Src >
constexpr std::make_signed< typenamebase::internal::UnderlyingType< Src >::type >::type base::internal::as_signed ( const Src  value)
constexpr

Definition at line 672 of file safe_conversions_impl.h.

672 {
673 static_assert(std::is_integral<decltype(as_signed(value))>::value,
674 "Argument must be a signed or unsigned integer type.");
675 return static_cast<decltype(as_signed(value))>(value);
676}
static bool is_integral(const SkRect &r)
constexpr std::make_signed< typenamebase::internal::UnderlyingType< Src >::type >::type as_signed(const Src value)

◆ as_unsigned()

template<typename Src >
constexpr std::make_unsigned< typenamebase::internal::UnderlyingType< Src >::type >::type base::internal::as_unsigned ( const Src  value)
constexpr

Definition at line 684 of file safe_conversions_impl.h.

684 {
685 static_assert(std::is_integral<decltype(as_unsigned(value))>::value,
686 "Argument must be a signed or unsigned integer type.");
687 return static_cast<decltype(as_unsigned(value))>(value);
688}
constexpr std::make_unsigned< typenamebase::internal::UnderlyingType< Src >::type >::type as_unsigned(const Src value)

◆ CanDetectCompileTimeConstant()

constexpr bool base::internal::CanDetectCompileTimeConstant ( )
constexpr

Definition at line 97 of file safe_conversions_impl.h.

97 {
98 return false;
99}

◆ checked_cast()

template<typename Dst , class CheckHandler = internal::CheckOnFailure, typename Src >
constexpr Dst base::internal::checked_cast ( Src  value)
constexpr

Definition at line 107 of file safe_conversions.h.

107 {
108 // This throws a compile-time error on evaluating the constexpr if it can be
109 // determined at compile-time as failing, otherwise it will CHECK at runtime.
111 return BASE_NUMERICS_LIKELY((IsValueInRangeForNumericType<Dst>(value)))
112 ? static_cast<Dst>(static_cast<SrcType>(value))
113 : CheckHandler::template HandleFailure<Dst>();
114}
#define BASE_NUMERICS_LIKELY(x)
typename ArithmeticOrUnderlyingEnum< T >::type type
SrcType
Definition: xfermodes.cpp:29

◆ CheckedAddImpl()

template<typename T >
constexpr bool base::internal::CheckedAddImpl ( T  x,
T  y,
T result 
)
constexpr

Definition at line 23 of file checked_math_impl.h.

23 {
24 static_assert(std::is_integral<T>::value, "Type must be integral");
25 // Since the value of x+y is undefined if we have a signed type, we compute
26 // it using the unsigned type of the same size.
27 using UnsignedDst = typename std::make_unsigned<T>::type;
28 using SignedDst = typename std::make_signed<T>::type;
29 UnsignedDst ux = static_cast<UnsignedDst>(x);
30 UnsignedDst uy = static_cast<UnsignedDst>(y);
31 UnsignedDst uresult = static_cast<UnsignedDst>(ux + uy);
32 *result = static_cast<T>(uresult);
33 // Addition is valid if the sign of (x + y) is equal to either that of x or
34 // that of y.
36 ? static_cast<SignedDst>((uresult ^ ux) & (uresult ^ uy)) >= 0
37 : uresult >= uy; // Unsigned is either valid or underflow.
38}
GLenum type
GAsyncResult * result
double y
double x

◆ CheckedMulImpl()

template<typename T >
constexpr bool base::internal::CheckedMulImpl ( T  x,
T  y,
T result 
)
constexpr

Definition at line 143 of file checked_math_impl.h.

143 {
144 static_assert(std::is_integral<T>::value, "Type must be integral");
145 // Since the value of x*y is potentially undefined if we have a signed type,
146 // we compute it using the unsigned type of the same size.
147 using UnsignedDst = typename std::make_unsigned<T>::type;
148 using SignedDst = typename std::make_signed<T>::type;
149 const UnsignedDst ux = SafeUnsignedAbs(x);
150 const UnsignedDst uy = SafeUnsignedAbs(y);
151 UnsignedDst uresult = static_cast<UnsignedDst>(ux * uy);
152 const bool is_negative =
153 std::is_signed<T>::value && static_cast<SignedDst>(x ^ y) < 0;
154 *result = is_negative ? 0 - uresult : uresult;
155 // We have a fast out for unsigned identity or zero on the second operand.
156 // After that it's an unsigned overflow check on the absolute value, with
157 // a +1 bound for a negative result.
158 return uy <= UnsignedDst(!std::is_signed<T>::value || is_negative) ||
159 ux <= (std::numeric_limits<T>::max() + UnsignedDst(is_negative)) / uy;
160}
static float max(float r, float g, float b)
Definition: hsl.cpp:49

◆ CheckedSubImpl()

template<typename T >
constexpr bool base::internal::CheckedSubImpl ( T  x,
T  y,
T result 
)
constexpr

Definition at line 83 of file checked_math_impl.h.

83 {
84 static_assert(std::is_integral<T>::value, "Type must be integral");
85 // Since the value of x+y is undefined if we have a signed type, we compute
86 // it using the unsigned type of the same size.
87 using UnsignedDst = typename std::make_unsigned<T>::type;
88 using SignedDst = typename std::make_signed<T>::type;
89 UnsignedDst ux = static_cast<UnsignedDst>(x);
90 UnsignedDst uy = static_cast<UnsignedDst>(y);
91 UnsignedDst uresult = static_cast<UnsignedDst>(ux - uy);
92 *result = static_cast<T>(uresult);
93 // Subtraction is valid if either x and y have same sign, or (x-y) and x have
94 // the same sign.
96 ? static_cast<SignedDst>((uresult ^ ux) & (ux ^ uy)) >= 0
97 : x >= y;
98}

◆ CheckMathOp() [1/2]

template<template< typename, typename, typename > class M, typename L , typename R >
constexpr CheckedNumeric< typename MathWrapper< M, L, R >::type > base::internal::CheckMathOp ( const L  lhs,
const R  rhs 
)
constexpr

Definition at line 320 of file checked_math.h.

322 {
323 using Math = typename MathWrapper<M, L, R>::math;
325 rhs);
326}
M< typename UnderlyingType< L >::type, typename UnderlyingType< R >::type, void > math

◆ CheckMathOp() [2/2]

template<template< typename, typename, typename > class M, typename L , typename R , typename... Args>
constexpr CheckedNumeric< typename ResultType< M, L, R, Args... >::type > base::internal::CheckMathOp ( const L  lhs,
const R  rhs,
const Args...  args 
)
constexpr

Definition at line 334 of file checked_math.h.

334 {
335 return CheckMathOp<M>(CheckMathOp<M>(lhs, rhs), args...);
336}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

◆ ClampMathOp() [1/2]

template<template< typename, typename, typename > class M, typename L , typename R >
constexpr ClampedNumeric< typename MathWrapper< M, L, R >::type > base::internal::ClampMathOp ( const L  lhs,
const R  rhs 
)
constexpr

Definition at line 207 of file clamped_math.h.

209 {
210 using Math = typename MathWrapper<M, L, R>::math;
212 rhs);
213}

◆ ClampMathOp() [2/2]

template<template< typename, typename, typename > class M, typename L , typename R , typename... Args>
constexpr ClampedNumeric< typename ResultType< M, L, R, Args... >::type > base::internal::ClampMathOp ( const L  lhs,
const R  rhs,
const Args...  args 
)
constexpr

Definition at line 221 of file clamped_math.h.

221 {
222 return ClampMathOp<M>(ClampMathOp<M>(lhs, rhs), args...);
223}

◆ CommonMax()

template<typename Dst , typename Src >
constexpr Dst base::internal::CommonMax ( )
constexpr

Definition at line 824 of file safe_conversions_impl.h.

824 {
825 return !IsMaxInRangeForNumericType<Dst, Src>()
827 : Dst(std::numeric_limits<Src>::max());
828}
Definition: ref_ptr.h:256

◆ CommonMaxOrMin()

template<typename Dst , typename Src = Dst>
constexpr Dst base::internal::CommonMaxOrMin ( bool  is_min)
constexpr

Definition at line 841 of file safe_conversions_impl.h.

841 {
842 return is_min ? CommonMin<Dst, Src>() : CommonMax<Dst, Src>();
843}
constexpr Dst CommonMax()

◆ CommonMin()

template<typename Dst , typename Src >
constexpr Dst base::internal::CommonMin ( )
constexpr

Definition at line 831 of file safe_conversions_impl.h.

831 {
832 return !IsMinInRangeForNumericType<Dst, Src>()
833 ? Dst(std::numeric_limits<Dst>::lowest())
834 : Dst(std::numeric_limits<Src>::lowest());
835}

◆ ConditionalNegate()

template<typename T >
constexpr std::make_signed< T >::type base::internal::ConditionalNegate ( T  x,
bool  is_negative 
)
constexpr

Definition at line 67 of file safe_conversions_impl.h.

69 {
70 static_assert(std::is_integral<T>::value, "Type must be integral");
71 using SignedT = typename std::make_signed<T>::type;
72 using UnsignedT = typename std::make_unsigned<T>::type;
73 return static_cast<SignedT>(
74 (static_cast<UnsignedT>(x) ^ -SignedT(is_negative)) + is_negative);
75}

◆ DstRangeRelationToSrcRange()

template<typename Dst , template< typename > class Bounds = std::numeric_limits, typename Src >
constexpr RangeCheck base::internal::DstRangeRelationToSrcRange ( Src  value)
constexpr

Definition at line 402 of file safe_conversions_impl.h.

402 {
403 static_assert(std::is_arithmetic<Src>::value, "Argument must be numeric.");
404 static_assert(std::is_arithmetic<Dst>::value, "Result must be numeric.");
405 static_assert(Bounds<Dst>::lowest() < Bounds<Dst>::max(), "");
407}
def Check(request)
Definition: tester.py:24

◆ INTEGER_FOR_DIGITS_AND_SIGN() [1/8]

base::internal::INTEGER_FOR_DIGITS_AND_SIGN ( int16_t  )

◆ INTEGER_FOR_DIGITS_AND_SIGN() [2/8]

base::internal::INTEGER_FOR_DIGITS_AND_SIGN ( int32_t  )

◆ INTEGER_FOR_DIGITS_AND_SIGN() [3/8]

base::internal::INTEGER_FOR_DIGITS_AND_SIGN ( int64_t  )

◆ INTEGER_FOR_DIGITS_AND_SIGN() [4/8]

base::internal::INTEGER_FOR_DIGITS_AND_SIGN ( int8_t  )

◆ INTEGER_FOR_DIGITS_AND_SIGN() [5/8]

base::internal::INTEGER_FOR_DIGITS_AND_SIGN ( uint16_t  )

◆ INTEGER_FOR_DIGITS_AND_SIGN() [6/8]

base::internal::INTEGER_FOR_DIGITS_AND_SIGN ( uint32_t  )

◆ INTEGER_FOR_DIGITS_AND_SIGN() [7/8]

base::internal::INTEGER_FOR_DIGITS_AND_SIGN ( uint64_t  )

◆ INTEGER_FOR_DIGITS_AND_SIGN() [8/8]

base::internal::INTEGER_FOR_DIGITS_AND_SIGN ( uint8_t  )

◆ InvertWrapper()

template<typename T , typename std::enable_if< std::is_integral< T >::value >::type * = nullptr>
constexpr std::make_unsigned< T >::type base::internal::InvertWrapper ( T  value)
constexpr

Definition at line 153 of file safe_math_shared_impl.h.

153 {
154 return ~value;
155}

◆ IsCompileTimeConstant()

template<typename T >
constexpr bool base::internal::IsCompileTimeConstant ( const  T)
constexpr

Definition at line 101 of file safe_conversions_impl.h.

101 {
102 return false;
103}

◆ IsGreaterImpl()

template<typename L , typename R >
constexpr bool base::internal::IsGreaterImpl ( const L  lhs,
const R  rhs,
const RangeCheck  l_range,
const RangeCheck  r_range 
)
constexpr

Definition at line 731 of file safe_conversions_impl.h.

734 {
735 return l_range.IsOverflow() || r_range.IsUnderflow() ||
736 (l_range == r_range && static_cast<decltype(lhs + rhs)>(lhs) >
737 static_cast<decltype(lhs + rhs)>(rhs));
738}
constexpr bool IsOverflow() const
constexpr bool IsUnderflow() const

◆ IsGreaterOrEqualImpl()

template<typename L , typename R >
constexpr bool base::internal::IsGreaterOrEqualImpl ( const L  lhs,
const R  rhs,
const RangeCheck  l_range,
const RangeCheck  r_range 
)
constexpr

Definition at line 751 of file safe_conversions_impl.h.

754 {
755 return l_range.IsOverflow() || r_range.IsUnderflow() ||
756 (l_range == r_range && static_cast<decltype(lhs + rhs)>(lhs) >=
757 static_cast<decltype(lhs + rhs)>(rhs));
758}

◆ IsLessImpl()

template<typename L , typename R >
constexpr bool base::internal::IsLessImpl ( const L  lhs,
const R  rhs,
const RangeCheck  l_range,
const RangeCheck  r_range 
)
constexpr

Definition at line 691 of file safe_conversions_impl.h.

694 {
695 return l_range.IsUnderflow() || r_range.IsOverflow() ||
696 (l_range == r_range && static_cast<decltype(lhs + rhs)>(lhs) <
697 static_cast<decltype(lhs + rhs)>(rhs));
698}

◆ IsLessOrEqualImpl()

template<typename L , typename R >
constexpr bool base::internal::IsLessOrEqualImpl ( const L  lhs,
const R  rhs,
const RangeCheck  l_range,
const RangeCheck  r_range 
)
constexpr

Definition at line 711 of file safe_conversions_impl.h.

714 {
715 return l_range.IsUnderflow() || r_range.IsOverflow() ||
716 (l_range == r_range && static_cast<decltype(lhs + rhs)>(lhs) <=
717 static_cast<decltype(lhs + rhs)>(rhs));
718}

◆ IsMaxInRangeForNumericType()

template<typename Dst , typename Src >
constexpr bool base::internal::IsMaxInRangeForNumericType ( )
constexpr

◆ IsMinInRangeForNumericType()

template<typename Dst , typename Src >
constexpr bool base::internal::IsMinInRangeForNumericType ( )
constexpr

Definition at line 818 of file safe_conversions_impl.h.

818 {
819 return IsLessOrEqual<Dst, Src>::Test(std::numeric_limits<Dst>::lowest(),
820 std::numeric_limits<Src>::lowest());
821}

◆ IsValidForType()

template<typename Dst , typename Src >
constexpr bool base::internal::IsValidForType ( const CheckedNumeric< Src >  value)
constexpr

Definition at line 291 of file checked_math.h.

291 {
292 return value.template IsValid<Dst>();
293}

◆ IsValueInRangeForNumericType()

template<typename Dst , typename Src >
constexpr bool base::internal::IsValueInRangeForNumericType ( Src  value)
constexpr

Definition at line 91 of file safe_conversions.h.

◆ IsValueNegative()

template<typename T , typename std::enable_if< std::is_signed< T >::value >::type * = nullptr>
constexpr bool base::internal::IsValueNegative ( T  value)
constexpr

Definition at line 51 of file safe_conversions_impl.h.

51 {
52 static_assert(std::is_arithmetic<T>::value, "Argument must be numeric.");
53 return value < 0;
54}

◆ MakeCheckedNum()

template<typename T >
constexpr CheckedNumeric< typename UnderlyingType< T >::type > base::internal::MakeCheckedNum ( const T  value)
constexpr

Definition at line 311 of file checked_math.h.

312 {
313 return value;
314}

◆ MakeClampedNum()

template<typename T >
constexpr ClampedNumeric< typename UnderlyingType< T >::type > base::internal::MakeClampedNum ( const T  value)
constexpr

Definition at line 189 of file clamped_math.h.

190 {
191 return value;
192}

◆ MakeStrictNum()

template<typename T >
constexpr StrictNumeric< typename UnderlyingType< T >::type > base::internal::MakeStrictNum ( const T  value)
constexpr

Definition at line 312 of file safe_conversions.h.

313 {
314 return value;
315}

◆ MustTreatAsConstexpr()

template<typename T >
constexpr bool base::internal::MustTreatAsConstexpr ( const T  v)
constexpr

Definition at line 106 of file safe_conversions_impl.h.

106 {
107 // Either we can't detect a compile-time constant, and must always use the
108 // constexpr path, or we know we have a compile-time constant.
110}
constexpr bool IsCompileTimeConstant(const T)
constexpr bool CanDetectCompileTimeConstant()

◆ NegateWrapper()

template<typename T , typename std::enable_if< std::is_integral< T >::value >::type * = nullptr>
constexpr T base::internal::NegateWrapper ( T  value)
constexpr

Definition at line 138 of file safe_math_shared_impl.h.

138 {
139 using UnsignedT = typename std::make_unsigned<T>::type;
140 // This will compile to a NEG on Intel, and is normal negation on ARM.
141 return static_cast<T>(UnsignedT(0) - static_cast<UnsignedT>(value));
142}

◆ operator+()

template<typename L , typename R >
L * base::internal::operator+ ( L *  lhs,
const StrictNumeric< R rhs 
)

Definition at line 355 of file checked_math.h.

355 {
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);
360}
#define R(r)

◆ operator-()

template<typename L , typename R >
L * base::internal::operator- ( L *  lhs,
const StrictNumeric< R rhs 
)

Definition at line 363 of file checked_math.h.

363 {
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);
368}

◆ operator<<() [1/2]

template<typename T >
std::ostream & base::internal::operator<< ( std::ostream &  os,
const ClampedNumeric< T > &  value 
)

Definition at line 197 of file clamped_math.h.

197 {
198 os << static_cast<T>(value);
199 return os;
200}

◆ operator<<() [2/2]

template<typename T >
std::ostream & base::internal::operator<< ( std::ostream &  os,
const StrictNumeric< T > &  value 
)

Definition at line 320 of file safe_conversions.h.

320 {
321 os << static_cast<T>(value);
322 return os;
323}

◆ SafeCompare()

template<template< typename, typename > class C, typename L , typename R >
constexpr bool base::internal::SafeCompare ( const L  lhs,
const R  rhs 
)
constexpr

Definition at line 797 of file safe_conversions_impl.h.

797 {
799 "Types must be numeric.");
800 using Promotion = BigEnoughPromotion<L, R>;
801 using BigType = typename Promotion::type;
802 return Promotion::is_contained
803 // Force to a larger type for speed if both are contained.
805 static_cast<BigType>(static_cast<L>(lhs)),
806 static_cast<BigType>(static_cast<R>(rhs)))
807 // Let the template functions figure it out for mixed types.
808 : C<L, R>::Test(lhs, rhs);
809}

◆ SafeUnsignedAbs()

template<typename T >
constexpr std::make_unsigned< T >::type base::internal::SafeUnsignedAbs ( T  value)
constexpr

Definition at line 79 of file safe_conversions_impl.h.

79 {
80 static_assert(std::is_integral<T>::value, "Type must be integral");
81 using UnsignedT = typename std::make_unsigned<T>::type;
83 ? static_cast<UnsignedT>(0u - static_cast<UnsignedT>(value))
84 : static_cast<UnsignedT>(value);
85}
constexpr bool IsValueNegative(T value)

◆ saturated_cast()

template<typename Dst , template< typename > class SaturationHandler = SaturationDefaultLimits, typename Src >
constexpr Dst base::internal::saturated_cast ( Src  value)
constexpr

Definition at line 206 of file safe_conversions.h.

206 {
207 using SrcType = typename UnderlyingType<Src>::type;
208 return !IsCompileTimeConstant(value) &&
210 std::is_same<SaturationHandler<Dst>,
213 : saturated_cast_impl<Dst, SaturationHandler, SrcType>(
214 static_cast<SrcType>(value),
215 DstRangeRelationToSrcRange<Dst, SaturationHandler, SrcType>(
216 static_cast<SrcType>(value)));
217}
constexpr Dst saturated_cast_impl(Src value, RangeCheck constraint)

◆ saturated_cast_impl()

template<typename Dst , template< typename > class S, typename Src >
constexpr Dst base::internal::saturated_cast_impl ( Src  value,
RangeCheck  constraint 
)
constexpr

Definition at line 141 of file safe_conversions.h.

141 {
142 // For some reason clang generates much better code when the branch is
143 // structured exactly this way, rather than a sequence of checks.
144 return !constraint.IsOverflowFlagSet()
145 ? (!constraint.IsUnderflowFlagSet() ? static_cast<Dst>(value)
146 : S<Dst>::Underflow())
147 // Skip this check for integral Src, which cannot be NaN.
149 ? S<Dst>::Overflow()
150 : S<Dst>::NaN());
151}
constexpr bool IsOverflowFlagSet() const
constexpr bool IsUnderflowFlagSet() const

◆ SaturatedAbsWrapper()

template<typename T , typename std::enable_if< std::is_integral< T >::value >::type * = nullptr>
constexpr T base::internal::SaturatedAbsWrapper ( T  value)
constexpr

Definition at line 50 of file clamped_math_impl.h.

50 {
51 // The calculation below is a static identity for unsigned types, but for
52 // signed integer types it provides a non-branching, saturated absolute value.
53 // This works because SafeUnsignedAbs() returns an unsigned type, which can
54 // represent the absolute value of all negative numbers of an equal-width
55 // integer type. The call to IsValueNegative() then detects overflow in the
56 // special case of numeric_limits<T>::min(), by evaluating the bit pattern as
57 // a signed integer value. If it is the overflow case, we end up subtracting
58 // one from the unsigned result, thus saturating to numeric_limits<T>::max().
59 return static_cast<T>(SafeUnsignedAbs(value) -
60 IsValueNegative<T>(SafeUnsignedAbs(value)));
61}

◆ SaturatedNegWrapper()

template<typename T , typename std::enable_if< std::is_integral< T >::value &&std::is_signed< T >::value >::type * = nullptr>
constexpr T base::internal::SaturatedNegWrapper ( T  value)
constexpr

Definition at line 26 of file clamped_math_impl.h.

26 {
28 ? (NegateWrapper(value) != std::numeric_limits<T>::lowest()
30 : std::numeric_limits<T>::max())
31 : ClampedNegFastOp<T>::Do(value);
32}
constexpr T NegateWrapper(T value)
constexpr bool MustTreatAsConstexpr(const T v)

◆ strict_cast()

template<typename Dst , typename Src >
constexpr Dst base::internal::strict_cast ( Src  value)
constexpr

Definition at line 223 of file safe_conversions.h.

223 {
224 using SrcType = typename UnderlyingType<Src>::type;
225 static_assert(UnderlyingType<Src>::is_numeric, "Argument must be numeric.");
226 static_assert(std::is_arithmetic<Dst>::value, "Result must be numeric.");
227
228 // If you got here from a compiler error, it's because you tried to assign
229 // from a source type to a destination type that has insufficient range.
230 // The solution may be to change the destination type you're assigning to,
231 // and use one large enough to represent the source.
232 // Alternatively, you may be better served with the checked_cast<> or
233 // saturated_cast<> template functions for your particular use case.
236 "The source type is out of range for the destination type. "
237 "Please see strict_cast<> comments for more information.");
238
239 return static_cast<Dst>(static_cast<SrcType>(value));
240}

◆ ValueOrDefaultForType()

template<typename Dst , typename Src , typename Default >
constexpr StrictNumeric< Dst > base::internal::ValueOrDefaultForType ( const CheckedNumeric< Src >  value,
const Default  default_value 
)
constexpr

Definition at line 302 of file checked_math.h.

304 {
305 return value.template ValueOrDefault<Dst>(default_value);
306}

◆ ValueOrDieForType()

template<typename Dst , typename Src >
constexpr StrictNumeric< Dst > base::internal::ValueOrDieForType ( const CheckedNumeric< Src >  value)
constexpr

Definition at line 296 of file checked_math.h.

297 {
298 return value.template ValueOrDie<Dst>();
299}