Chromium Code Reviews| Index: base/numerics/safe_conversions_impl.h |
| diff --git a/base/numerics/safe_conversions_impl.h b/base/numerics/safe_conversions_impl.h |
| index c52b8f25c77f10bd4d9babd7560c329eed52d0bd..be9eaa16ba6008a58c6fa33e5a5ad83b37385c8c 100644 |
| --- a/base/numerics/safe_conversions_impl.h |
| +++ b/base/numerics/safe_conversions_impl.h |
| @@ -335,11 +335,7 @@ enum ArithmeticPromotionCategory { |
| RIGHT_PROMOTION // Use the type of the right-hand argument. |
| }; |
| -template <ArithmeticPromotionCategory Promotion, |
| - typename Lhs, |
| - typename Rhs = Lhs> |
| -struct ArithmeticPromotion; |
| - |
| +// Determines the type that can represent the largest positive value. |
| template <typename Lhs, |
| typename Rhs, |
| ArithmeticPromotionCategory Promotion = |
| @@ -358,6 +354,34 @@ struct MaxExponentPromotion<Lhs, Rhs, RIGHT_PROMOTION> { |
| using type = Rhs; |
| }; |
| +// Determines the type that can represent the lowest arithmetic value. |
|
dcheng
2016/12/03 21:34:29
Nit: it kind of feels like we should be more consi
jschuh
2016/12/03 22:29:12
I tried to be consistent with std::numeric_limits<
|
| +template <typename Lhs, |
| + typename Rhs, |
| + ArithmeticPromotionCategory Promotion = |
| + std::is_signed<Lhs>::value |
| + ? (std::is_signed<Rhs>::value |
| + ? (MaxExponent<Lhs>::value > MaxExponent<Rhs>::value |
| + ? LEFT_PROMOTION |
| + : RIGHT_PROMOTION) |
| + : LEFT_PROMOTION) |
| + : (std::is_signed<Rhs>::value |
| + ? RIGHT_PROMOTION |
| + : (MaxExponent<Lhs>::value < MaxExponent<Rhs>::value |
| + ? LEFT_PROMOTION |
| + : RIGHT_PROMOTION))> |
| +struct LowestValuePromotion; |
| + |
| +template <typename Lhs, typename Rhs> |
| +struct LowestValuePromotion<Lhs, Rhs, LEFT_PROMOTION> { |
| + using type = Lhs; |
| +}; |
| + |
| +template <typename Lhs, typename Rhs> |
| +struct LowestValuePromotion<Lhs, Rhs, RIGHT_PROMOTION> { |
| + using type = Rhs; |
| +}; |
| + |
| +// Determines the type that is best able to represent an arithmetic result. |
| template <typename Lhs, |
| typename Rhs = Lhs, |
| bool is_intmax_type = |