Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1053)

Unified Diff: base/numerics/safe_math.h

Issue 2510973002: Add support for CheckedNumeric bitshift operators (Closed)
Patch Set: format Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/numerics/safe_math_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/numerics/safe_math.h
diff --git a/base/numerics/safe_math.h b/base/numerics/safe_math.h
index 41aa0515c1dfb17b2feccf28cff379965d720e18..511eb23f78763c929e86db014f08911d17d0acf2 100644
--- a/base/numerics/safe_math.h
+++ b/base/numerics/safe_math.h
@@ -112,11 +112,20 @@ class CheckedNumeric {
T ValueUnsafe() const { return state_.value(); }
// Prototypes for the supported arithmetic operator overloads.
- template <typename Src> CheckedNumeric& operator+=(Src rhs);
- template <typename Src> CheckedNumeric& operator-=(Src rhs);
- template <typename Src> CheckedNumeric& operator*=(Src rhs);
- template <typename Src> CheckedNumeric& operator/=(Src rhs);
- template <typename Src> CheckedNumeric& operator%=(Src rhs);
+ template <typename Src>
+ CheckedNumeric& operator+=(Src rhs);
+ template <typename Src>
+ CheckedNumeric& operator-=(Src rhs);
+ template <typename Src>
+ CheckedNumeric& operator*=(Src rhs);
+ template <typename Src>
+ CheckedNumeric& operator/=(Src rhs);
+ template <typename Src>
+ CheckedNumeric& operator%=(Src rhs);
+ template <typename Src>
+ CheckedNumeric& operator<<=(Src rhs);
+ template <typename Src>
+ CheckedNumeric& operator>>=(Src rhs);
CheckedNumeric operator-() const {
// Negation is always valid for floating point.
@@ -240,6 +249,8 @@ BASE_NUMERIC_ARITHMETIC_OPERATORS(Sub, -, -=, MAX_EXPONENT_PROMOTION)
BASE_NUMERIC_ARITHMETIC_OPERATORS(Mul, *, *=, MAX_EXPONENT_PROMOTION)
BASE_NUMERIC_ARITHMETIC_OPERATORS(Div, /, /=, MAX_EXPONENT_PROMOTION)
BASE_NUMERIC_ARITHMETIC_OPERATORS(Mod, %, %=, MAX_EXPONENT_PROMOTION)
+BASE_NUMERIC_ARITHMETIC_OPERATORS(LeftShift, <<, <<=, LEFT_PROMOTION)
+BASE_NUMERIC_ARITHMETIC_OPERATORS(RightShift, >>, >>=, LEFT_PROMOTION)
#undef BASE_NUMERIC_ARITHMETIC_OPERATORS
« no previous file with comments | « no previous file | base/numerics/safe_math_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698