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

Unified Diff: base/numerics/safe_conversions.h

Issue 2545253002: Add support for CheckedNumeric Max and Min constexpr functions (Closed)
Patch Set: stupid compilers with weak constexpr float support Created 4 years 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_conversions_impl.h » ('j') | base/numerics/safe_conversions_impl.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/numerics/safe_conversions.h
diff --git a/base/numerics/safe_conversions.h b/base/numerics/safe_conversions.h
index 71408102eabc4843493cf46e086129c766dcce8e..7dca58781a1d2afd040b1433082dfc8011a9e2d0 100644
--- a/base/numerics/safe_conversions.h
+++ b/base/numerics/safe_conversions.h
@@ -42,6 +42,8 @@ namespace base {
// across any range of arithmetic types. StrictNumeric is the return type
// for values extracted from a CheckedNumeric class instance. The raw
// arithmetic value is extracted via static_cast to the underlying type.
+// StrictNum() - Creates a new StrictNumeric from the underlying type of the
+// supplied arithmetic or StrictNumeric type.
// Convenience function that returns true if the supplied value is in range
// for the destination type.
@@ -229,6 +231,13 @@ class StrictNumeric {
const T value_;
};
+// Convience wrapper returns a StrictNumeric from the provided arithmetic type.
+template <typename T>
+constexpr StrictNumeric<typename UnderlyingType<T>::type> StrictNum(
dcheng 2016/12/03 21:34:29 Nit: usually we name the deducing helpers MakeFoo,
jschuh 2016/12/03 22:29:12 Fair. I'll fix it here and convert CheckNum to Mak
dcheng 2016/12/04 01:42:14 MakeStrict / MakeChecked almost feel too generic (
+ const T value) {
+ return value;
+}
+
// Overload the ostream output operator to make logging work nicely.
template <typename T>
std::ostream& operator<<(std::ostream& os, const StrictNumeric<T>& value) {
@@ -258,6 +267,7 @@ STRICT_COMPARISON_OP(IsNotEqual, !=);
using internal::strict_cast;
using internal::saturated_cast;
using internal::StrictNumeric;
+using internal::StrictNum;
// Explicitly make a shorter size_t typedef for convenience.
typedef StrictNumeric<size_t> SizeT;
« no previous file with comments | « no previous file | base/numerics/safe_conversions_impl.h » ('j') | base/numerics/safe_conversions_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698