template <typename T>

class CheckedNumeric

Defined at line 22 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

The following are helper templates used in the CheckedNumeric class.

Public Methods

void CheckedNumeric<T> ()

Defined at line 26 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
void CheckedNumeric<T> (const CheckedNumeric<Src> & rhs)

Copy constructor.

Defined at line 30 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
void CheckedNumeric<T> (Src value)

NOLINTNEXTLINE(google-explicit-constructor)

Defined at line 38 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
void CheckedNumeric<T> (StrictNumeric<Src> value)

NOLINTNEXTLINE(google-explicit-constructor)

Defined at line 44 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Dst = T>
bool IsValid ()

IsValid() - The public API to test if a CheckedNumeric is currently valid.

A range checked destination type can be supplied using the Dst template

parameter.

Defined at line 51 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Predicate>
bool IsValidAnd (Predicate && predicate)

Returns true if all the following are true:

- `this` is valid

- the underlying value can be represented by the type of

`predicate`'s single parameter.

- `predicate(underlying_value)` evaluates to true

`predicate` must take a single argument of arithmetic by value and return

a `bool`.

Example:

CheckedNumeric

<int

> zero;

if (zero.IsValidAnd([] (int x) { return x == 0; })) { ... }

Defined at line 70 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Predicate>
bool IsInvalidOr (Predicate && predicate)

Returns true if any of the following are true:

- `this` is invalid

- the underlying value cannot be represented by the type of

`predicate`'s single parameter.

- `predicate` evaluates to true

`predicate` must take a single argument of arithmetic by value and return

a `bool`.

Example:

CheckedNumeric

<int

> out_of_range = std::numeric_limits

<int

>::max();

if (out_of_range.IsInvalidOr([] (int x) { return x > 1024; })) { ... }

Defined at line 90 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Dst>
bool AssignIfValid (Dst * result)

Defined at line 101 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Dst = T, class CheckHandler = CheckOnFailure>
StrictNumeric<Dst> ValueOrDie ()

ValueOrDie() - The primary accessor for the underlying value. If the

current state is not valid it will CHECK and crash.

A range checked destination type can be supplied using the Dst template

parameter, which will trigger a CHECK if the value is not in bounds for

the destination.

The CHECK behavior can be overridden by supplying a handler as a

template parameter, for test code, etc. However, the handler cannot access

the underlying value, and it is not available through other means.

Defined at line 122 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Dst = T, typename Src>
StrictNumeric<Dst> ValueOrDefault (Src default_value)

ValueOrDefault(T default_value) - A convenience method that returns the

current value if the state is valid, and the supplied default_value for

any other state.

A range checked destination type can be supplied using the Dst template

parameter. WARNING: This function may fail to compile or CHECK at runtime

if the supplied default_value is not within range of the destination type.

Defined at line 136 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Dst>
CheckedNumeric<UnderlyingType<Dst>> Cast ()

Returns a checked numeric of the specified type, cast from the current

CheckedNumeric. If the current state is invalid or the destination cannot

represent the result then the returned CheckedNumeric will be invalid.

Defined at line 147 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

CheckedNumeric<T> operator- ()

Defined at line 179 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

CheckedNumeric<T> operator~ ()

Defined at line 193 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

CheckedNumeric<T> Abs ()

Defined at line 198 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename U>
CheckedNumeric<typename MathWrapper<CheckedMaxOp, T, U>::type> Max (U rhs)

Defined at line 203 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename U>
CheckedNumeric<typename MathWrapper<CheckedMinOp, T, U>::type> Min (U rhs)

Defined at line 209 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

CheckedNumeric<typename UnsignedOrFloatForSize<T>::type> UnsignedAbs ()

This function is available only for integral types. It returns an unsigned

integer of the same width as the source type, containing the absolute value

of the source, and properly handling signed min.

Defined at line 217 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

CheckedNumeric<T> & operator++ ()

Defined at line 223 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

CheckedNumeric<T> operator++ (int )

Defined at line 228 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

CheckedNumeric<T> & operator-- ()

Defined at line 234 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

CheckedNumeric<T> operator-- (int )

Defined at line 239 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <template <typename, typename> class M, typename L, typename R>
CheckedNumeric<T> MathOp (L lhs, R rhs)

These perform the actual math operations on the CheckedNumerics.

Binary arithmetic operations.

Defined at line 248 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <template <typename, typename> class M, typename R>
CheckedNumeric<T> & MathOp (R rhs)

Assignment arithmetic operations.

Defined at line 259 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
CheckedNumeric<T> & operator+= (const Src rhs)

Prototypes for the supported arithmetic operator overloads.

Defined at line 353 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
CheckedNumeric<T> & operator-= (const Src rhs)

Assignment arithmetic operator implementation from CLASS##Numeric.

Defined at line 354 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
CheckedNumeric<T> & operator*= (const Src rhs)

Assignment arithmetic operator implementation from CLASS##Numeric.

Defined at line 355 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
CheckedNumeric<T> & operator/= (const Src rhs)

Assignment arithmetic operator implementation from CLASS##Numeric.

Defined at line 356 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
CheckedNumeric<T> & operator%= (const Src rhs)

Assignment arithmetic operator implementation from CLASS##Numeric.

Defined at line 357 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
CheckedNumeric<T> & operator<<= (const Src rhs)

Assignment arithmetic operator implementation from CLASS##Numeric.

Defined at line 358 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
CheckedNumeric<T> & operator>>= (const Src rhs)

Assignment arithmetic operator implementation from CLASS##Numeric.

Defined at line 359 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
CheckedNumeric<T> & operator&= (const Src rhs)

Assignment arithmetic operator implementation from CLASS##Numeric.

Defined at line 360 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
CheckedNumeric<T> & operator|= (const Src rhs)

Assignment arithmetic operator implementation from CLASS##Numeric.

Defined at line 361 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

template <typename Src>
CheckedNumeric<T> & operator^= (const Src rhs)

Assignment arithmetic operator implementation from CLASS##Numeric.

Defined at line 362 of file ../../zircon/third_party/ulib/safemath/include/safemath/checked_math.h

Records

Friends

template <typename U>
class CheckedNumeric
template <typename U>
U CheckedNumeric (const CheckedNumeric<U> & src)