Home | History | Annotate | Download | only in numerics

Lines Matching defs:CheckedNumeric

20 // CheckedNumeric implements all the logic and operators for detecting integer
22 // The CheckedNumeric type implicitly converts from floating point and integer
26 // The following methods convert from CheckedNumeric to standard numeric values:
34 // only for floating point CheckedNumeric types).
42 // CheckedNumeric<int> checked_int = untrusted_input_value;
45 // CheckedNumeric<size_t> checked_size = untrusted_input_value;
50 class CheckedNumeric {
52 "CheckedNumeric<T>: T must be a numeric type.");
57 CheckedNumeric() {}
61 CheckedNumeric(const CheckedNumeric<Src>& rhs)
65 CheckedNumeric(Src value, RangeConstraint validity)
71 CheckedNumeric(Src value) // NOLINT(runtime/explicit)
80 CheckedNumeric(StrictNumeric<Src> value) // NOLINT(runtime/explicit)
84 // IsValid() is the public API to test if a CheckedNumeric is currently valid.
106 return CheckedNumeric<T>::cast(*this).ValueUnsafe();
128 template <typename Src> CheckedNumeric& operator+=(Src rhs);
129 template <typename Src> CheckedNumeric& operator-=(Src rhs);
130 template <typename Src> CheckedNumeric& operator*=(Src rhs);
131 template <typename Src> CheckedNumeric& operator/=(Src rhs);
132 template <typename Src> CheckedNumeric& operator%=(Src rhs);
134 CheckedNumeric operator-() const {
139 return CheckedNumeric<T>(value);
142 return CheckedNumeric<T>(value, validity);
145 CheckedNumeric Abs() const {
150 return CheckedNumeric<T>(value);
153 return CheckedNumeric<T>(value, validity);
159 CheckedNumeric<typename UnsignedOrFloatForSize<T>::type> UnsignedAbs() const {
160 return CheckedNumeric<typename UnsignedOrFloatForSize<T>::type>(
164 CheckedNumeric& operator++() {
169 CheckedNumeric operator++(int) {
170 CheckedNumeric value = *this;
175 CheckedNumeric& operator--() {
180 CheckedNumeric operator--(int) {
181 CheckedNumeric value = *this;
187 // the desired CheckedNumeric type. As an optimization, a reference is
190 static CheckedNumeric<T> cast(
198 static CheckedNumeric<T> cast(
199 const CheckedNumeric<Src>& u,
204 static const CheckedNumeric<T>& cast(const CheckedNumeric<T>& u) { return u; }
213 struct UnderlyingType<CheckedNumeric<NumericType>> {
230 CheckedNumeric<typename ArithmeticPromotion<T>::type> operator OP( \
231 const CheckedNumeric<T>& lhs, const CheckedNumeric<T>& rhs) { \
235 return CheckedNumeric<T>(lhs.ValueUnsafe() OP rhs.ValueUnsafe()); \
237 return CheckedNumeric<Promotion>( \
244 return CheckedNumeric<Promotion>( \
248 /* Assignment arithmetic operator implementation from CheckedNumeric. */ \
251 CheckedNumeric<T>& CheckedNumeric<T>::operator COMPOUND_OP(Src rhs) { \
252 *this = CheckedNumeric<T>::cast(*this) \
253 OP CheckedNumeric<typename UnderlyingType<Src>::type>::cast(rhs); \
256 /* Binary arithmetic operator for CheckedNumeric of different type. */ \
258 CheckedNumeric<typename ArithmeticPromotion<T, Src>::type> operator OP( \
259 const CheckedNumeric<Src>& lhs, const CheckedNumeric<T>& rhs) { \
262 return CheckedNumeric<Promotion>( \
265 return CheckedNumeric<Promotion>::cast(lhs) \
266 OP CheckedNumeric<Promotion>::cast(rhs); \
268 /* Binary arithmetic operator for left CheckedNumeric and right numeric. */ \
272 CheckedNumeric<typename ArithmeticPromotion<T, Src>::type> operator OP( \
273 const CheckedNumeric<T>& lhs, Src rhs) { \
276 return CheckedNumeric<Promotion>(lhs.ValueUnsafe() OP rhs, \
278 return CheckedNumeric<Promotion>::cast(lhs) \
279 OP CheckedNumeric<Promotion>::cast(rhs); \
281 /* Binary arithmetic operator for left numeric and right CheckedNumeric. */ \
285 CheckedNumeric<typename ArithmeticPromotion<T, Src>::type> operator OP( \
286 Src lhs, const CheckedNumeric<T>& rhs) { \
289 return CheckedNumeric<Promotion>(lhs OP rhs.ValueUnsafe(), \
291 return CheckedNumeric<Promotion>::cast(lhs) \
292 OP CheckedNumeric<Promotion>::cast(rhs); \
305 using internal::CheckedNumeric;