Adds infinite addition and subtraction to time units.
This prepares for allowing use making arithmetic operators constexpr. This also makes it easier to use for comparisons with offsets. Now a > b + 10 ms works even if b is infinite. Bug: webrtc:9574 Change-Id: Ie36092b72c2ec0f0c541641199a39155f5a796f3 Reviewed-on: https://webrtc-review.googlesource.com/96820 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Sebastian Jansson <srte@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24530}
This commit is contained in:
committed by
Commit Bot
parent
16e27a1dc5
commit
88c1a9ecbc
@ -162,17 +162,23 @@ class Timestamp {
|
||||
return TimeDelta::us(us() - other.us());
|
||||
}
|
||||
Timestamp operator-(const TimeDelta& delta) const {
|
||||
RTC_DCHECK(!delta.IsPlusInfinity());
|
||||
if (IsInfinite() || delta.IsMinusInfinity())
|
||||
return Infinity();
|
||||
return Timestamp::us(us() - delta.us());
|
||||
}
|
||||
Timestamp operator+(const TimeDelta& delta) const {
|
||||
RTC_DCHECK(!delta.IsMinusInfinity());
|
||||
if (IsInfinite() || delta.IsPlusInfinity())
|
||||
return Infinity();
|
||||
return Timestamp::us(us() + delta.us());
|
||||
}
|
||||
Timestamp& operator-=(const TimeDelta& other) {
|
||||
microseconds_ -= other.us();
|
||||
*this = *this - other;
|
||||
return *this;
|
||||
}
|
||||
Timestamp& operator+=(const TimeDelta& other) {
|
||||
microseconds_ += other.us();
|
||||
*this = *this + other;
|
||||
return *this;
|
||||
}
|
||||
constexpr bool operator==(const Timestamp& other) const {
|
||||
|
||||
Reference in New Issue
Block a user