Home | History | Annotate | Download | only in numerics

Lines Matching defs:CheckedNumeric

19 // CheckedNumeric<> implements all the logic and operators for detecting integer
21 // The CheckedNumeric type implicitly converts from floating point and integer
29 // standard arithmetic or CheckedNumeric types, perform arithmetic operations,
30 // and return a CheckedNumeric result. The supported functions are:
46 // CheckedNumeric as a result of the operation:
57 // The following methods convert from CheckedNumeric to standard numeric values:
80 // between arithmetic types and CheckedNumeric types:
81 // CheckedNumeric::Cast<Dst>() - Instance method returning a CheckedNumeric
82 // derived from casting the current instance to a CheckedNumeric of
84 // MakeCheckedNum() - Creates a new CheckedNumeric from the underlying type of
85 // the supplied arithmetic, CheckedNumeric, or StrictNumeric type.
90 // CheckedNumeric<size_t> checked_size = untrusted_input_value;
96 class CheckedNumeric {
98 "CheckedNumeric<T>: T must be a numeric type.");
103 constexpr CheckedNumeric() {}
107 constexpr CheckedNumeric(const CheckedNumeric<Src>& rhs)
111 friend class CheckedNumeric;
116 constexpr CheckedNumeric(Src value) // NOLINT(runtime/explicit)
124 constexpr CheckedNumeric(
128 // IsValid() - The public API to test if a CheckedNumeric is currently valid.
173 // CheckedNumeric. If the current state is invalid or the destination cannot
174 // represent the result then the returned CheckedNumeric will be invalid.
176 constexpr CheckedNumeric<typename UnderlyingType<Dst>::type> Cast() const {
184 friend U GetNumericValueForTest(const CheckedNumeric<U>& src);
188 CheckedNumeric& operator+=(const Src rhs);
190 CheckedNumeric& operator-=(const Src rhs);
192 CheckedNumeric& operator*=(const Src rhs);
194 CheckedNumeric& operator/=(const Src rhs);
196 CheckedNumeric& operator%=(const Src rhs);
198 CheckedNumeric& operator<<=(const Src rhs);
200 CheckedNumeric& operator>>=(const Src rhs);
202 CheckedNumeric& operator&=(const Src rhs);
204 CheckedNumeric& operator|=(const Src rhs);
206 CheckedNumeric& operator^=(const Src rhs);
208 constexpr CheckedNumeric operator-() const {
209 return CheckedNumeric<T>(
217 constexpr CheckedNumeric operator~() const {
218 return CheckedNumeric<decltype(InvertWrapper(T()))>(
222 constexpr CheckedNumeric Abs() const {
223 return CheckedNumeric<T>(
231 constexpr CheckedNumeric<typename MathWrapper<CheckedMaxOp, T, U>::type> Max(
237 return CheckedNumeric<result_type>(
246 constexpr CheckedNumeric<typename MathWrapper<CheckedMinOp, T, U>::type> Min(
252 return CheckedNumeric<result_type>(
263 constexpr CheckedNumeric<typename UnsignedOrFloatForSize<T>::type>
265 return CheckedNumeric<typename UnsignedOrFloatForSize<T>::type>(
269 CheckedNumeric& operator++() {
274 CheckedNumeric operator++(int) {
275 CheckedNumeric value = *this;
280 CheckedNumeric& operator--() {
285 CheckedNumeric operator--(int) {
286 CheckedNumeric value = *this;
296 static CheckedNumeric MathOp(const L lhs, const R rhs) {
302 return CheckedNumeric<T>(result, is_valid);
307 CheckedNumeric& MathOp(const R rhs) {
312 *this = CheckedNumeric<T>(result, is_valid);
320 constexpr CheckedNumeric(Src value, bool is_valid)
324 // CheckedNumeric and POD arithmetic types.
332 struct Wrapper<CheckedNumeric<Src>> {
333 static constexpr bool is_valid(const CheckedNumeric<Src> v) {
336 static constexpr Src value(const CheckedNumeric<Src> v) {
352 constexpr bool IsValidForType(const CheckedNumeric<Src> value) {
358 const CheckedNumeric<Src> value) {
364 const CheckedNumeric<Src> value,
393 // Convience wrapper to return a new CheckedNumeric from the provided arithmetic
396 constexpr CheckedNumeric<typename UnderlyingType<T>::type> MakeCheckedNum(
405 CheckedNumeric
408 return CheckedNumeric<typename Math::result_type>::template MathOp<M>(lhs,
417 CheckedNumeric<typename ResultType<M, L, R, Args...>::type>
429 CheckedNumeric<typename ResultType<Checked##NAME##Op, L, R, Args...>::type> \
435 /* Binary arithmetic operator for all CheckedNumeric operations. */ \
439 CheckedNumeric<typename MathWrapper<Checked##NAME##Op, L, R>::type> \
443 /* Assignment arithmetic operator implementation from CheckedNumeric. */ \
446 CheckedNumeric<L>& CheckedNumeric<L>::operator COMPOUND_OP(const R rhs) { \
449 /* Variadic arithmetic functions that return CheckedNumeric. */ \
489 using internal::CheckedNumeric;