Chromium Code Reviews| 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; |