| Index: webrtc/base/mod_ops.h
|
| diff --git a/webrtc/base/mod_ops.h b/webrtc/base/mod_ops.h
|
| index 9e649b75d21a78ff9de977167ed2cb0a3bf08253..cf65fdd4df828e193694aeb0f42143e8e339db6e 100644
|
| --- a/webrtc/base/mod_ops.h
|
| +++ b/webrtc/base/mod_ops.h
|
| @@ -16,11 +16,6 @@
|
|
|
| #include "webrtc/base/checks.h"
|
|
|
| -#define MOD_OPS_ASSERT_TYPE_IS_UNSIGNED(T) \
|
| - static_assert(std::numeric_limits<T>::is_integer && \
|
| - !std::numeric_limits<T>::is_signed, \
|
| - "Type must be of unsigned integer.")
|
| -
|
| namespace webrtc {
|
|
|
| template <unsigned long M> // NOLINT
|
| @@ -42,7 +37,7 @@ inline unsigned long Subtract(unsigned long a, unsigned long b) { // NOLINT
|
| return a - sub;
|
| }
|
|
|
| -// Calculates the forward difference between two numbers.
|
| +// Calculates the forward difference between two wrapping numbers.
|
| //
|
| // Example:
|
| // uint8_t x = 253;
|
| @@ -64,13 +59,23 @@ inline unsigned long Subtract(unsigned long a, unsigned long b) { // NOLINT
|
| // #################################################
|
| // -->-----> |----->---
|
| //
|
| +template <typename T, T M>
|
| +inline T ForwardDiff(T a, T b) {
|
| + static_assert(std::is_unsigned<T>::value,
|
| + "Type must be an unsigned integer.");
|
| + RTC_DCHECK_LT(a, M);
|
| + RTC_DCHECK_LT(b, M);
|
| + return a <= b ? b - a : M - (a - b);
|
| +}
|
| +
|
| template <typename T>
|
| inline T ForwardDiff(T a, T b) {
|
| - MOD_OPS_ASSERT_TYPE_IS_UNSIGNED(T);
|
| + static_assert(std::is_unsigned<T>::value,
|
| + "Type must be an unsigned integer.");
|
| return b - a;
|
| }
|
|
|
| -// Calculates the reverse difference between two numbers.
|
| +// Calculates the reverse difference between two wrapping numbers.
|
| //
|
| // Example:
|
| // uint8_t x = 253;
|
| @@ -92,9 +97,19 @@ inline T ForwardDiff(T a, T b) {
|
| // #################################################
|
| // ---<-----| |<-----<--
|
| //
|
| +template <typename T, T M>
|
| +inline T ReverseDiff(T a, T b) {
|
| + static_assert(std::is_unsigned<T>::value,
|
| + "Type must be an unsigned integer.");
|
| + RTC_DCHECK_LT(a, M);
|
| + RTC_DCHECK_LT(b, M);
|
| + return b <= a ? a - b : M - (b - a);
|
| +}
|
| +
|
| template <typename T>
|
| inline T ReverseDiff(T a, T b) {
|
| - MOD_OPS_ASSERT_TYPE_IS_UNSIGNED(T);
|
| + static_assert(std::is_unsigned<T>::value,
|
| + "Type must be an unsigned integer.");
|
| return a - b;
|
| }
|
|
|
| @@ -104,7 +119,8 @@ inline T ReverseDiff(T a, T b) {
|
| // be ahead.
|
| template <typename T>
|
| inline bool AheadOrAt(T a, T b) {
|
| - MOD_OPS_ASSERT_TYPE_IS_UNSIGNED(T);
|
| + static_assert(std::is_unsigned<T>::value,
|
| + "Type must be an unsigned integer.");
|
| const T maxDist = std::numeric_limits<T>::max() / 2 + T(1);
|
| if (a - b == maxDist)
|
| return b < a;
|
| @@ -114,7 +130,8 @@ inline bool AheadOrAt(T a, T b) {
|
| // Test if sequence number a is ahead of sequence number b.
|
| template <typename T>
|
| inline bool AheadOf(T a, T b) {
|
| - MOD_OPS_ASSERT_TYPE_IS_UNSIGNED(T);
|
| + static_assert(std::is_unsigned<T>::value,
|
| + "Type must be an unsigned integer.");
|
| return a != b && AheadOrAt(a, b);
|
| }
|
|
|
|
|