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

Unified Diff: base/numerics/safe_math.h

Issue 1154543003: Add strictly checked numeric types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CheckedNumeric ctor and SizeT rename Created 5 years, 7 months 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 | « base/numerics/safe_conversions.h ('k') | base/numerics/safe_numerics_unittest.cc » ('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 1309446e195a73c960114c12fba2fd328de1525b..1fab032af0f449d825282b1c90307f231837985f 100644
--- a/base/numerics/safe_math.h
+++ b/base/numerics/safe_math.h
@@ -66,6 +66,13 @@ class CheckedNumeric {
"Argument must be numeric.");
}
+ // This is not an explicit constructor because we want a seamless conversion
+ // from StrictNumeric types.
+ template <typename Src>
+ CheckedNumeric(StrictNumeric<Src> value)
+ : state_(static_cast<Src>(value)) {
+ }
+
// IsValid() is the public API to test if a CheckedNumeric is currently valid.
bool IsValid() const { return validity() == RANGE_VALID; }
« no previous file with comments | « base/numerics/safe_conversions.h ('k') | base/numerics/safe_numerics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698