template <typename T>

class StrictNumeric

Defined at line 257 of file ../../zircon/third_party/ulib/safemath/include/safemath/safe_conversions.h

StrictNumeric implements compile time range checking between numeric types by

wrapping assignment operations in a strict_cast. This class is intended to be

used for function arguments and return types, to ensure the destination type

can always contain the source type. This is essentially the same as enforcing

-Wconversion in gcc and C4302 warnings on MSVC, but it can be applied

incrementally at API boundaries, making it easier to convert code so that it

compiles cleanly with truncation warnings enabled.

This template should introduce no runtime overhead, but it also provides no

runtime checking of any of the associated mathematical operations. Use

CheckedNumeric for runtime range checks of the actual value being assigned.

Public Methods

void StrictNumeric<T> ()

Defined at line 261 of file ../../zircon/third_party/ulib/safemath/include/safemath/safe_conversions.h

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

Copy constructor.

Defined at line 265 of file ../../zircon/third_party/ulib/safemath/include/safemath/safe_conversions.h

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

NOLINTNEXTLINE(google-explicit-constructor)

Defined at line 272 of file ../../zircon/third_party/ulib/safemath/include/safemath/safe_conversions.h

template <typename Dst>
Dst operator Dst ()

If you got here from a compiler error, it's because you tried to assign

from a source type to a destination type that has insufficient range.

The solution may be to change the destination type you're assigning to,

and use one large enough to represent the source.

If you're assigning from a CheckedNumeric

<

> class, you may be able to use

the AssignIfValid() member function, specify a narrower destination type to

the member value functions (e.g. val.template ValueOrDie

<Dst

>()), use one

of the value helper functions (e.g. ValueOrDieForType

<Dst

>(val)).

If you've encountered an _ambiguous overload_ you can use a static_cast

<

>

to explicitly cast the result to the destination type.

If none of that works, you may be better served with the checked_cast

<

> or

saturated_cast

<

> template functions for your particular use case.

Defined at line 288 of file ../../zircon/third_party/ulib/safemath/include/safemath/safe_conversions.h

bool operator! ()

Unary negation does not require any conversions.

Defined at line 293 of file ../../zircon/third_party/ulib/safemath/include/safemath/safe_conversions.h

Friends

template <typename U>
class StrictNumeric