template <typename T>
class StrictNumeric
Defined at line 264 of file ../../third_party/mini_chromium/src/base/numerics/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 268 of file ../../third_party/mini_chromium/src/base/numerics/safe_conversions.h
template <typename Src>
void StrictNumeric<T> (const StrictNumeric<Src> & rhs)
Copy constructor.
Defined at line 272 of file ../../third_party/mini_chromium/src/base/numerics/safe_conversions.h
template <typename Src>
void StrictNumeric<T> (Src value)
This is not an explicit constructor because we implicitly upgrade regular
numerics to StrictNumerics to make them easier to use.
Defined at line 278 of file ../../third_party/mini_chromium/src/base/numerics/safe_conversions.h
template <typename Dst, typename std::enable_if<
IsNumericRangeContained<Dst, T>::value>::type* = nullptr>
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 296 of file ../../third_party/mini_chromium/src/base/numerics/safe_conversions.h