Add default constructor to relative units types
0 is natural default value for types that can be accumulated Having default constructor simplify usage of these types in templated code. Bug: None Change-Id: If005c69018a2a11011bc789502fdbc600cad3278 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/369440 Reviewed-by: Per Kjellander <perkj@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Commit-Queue: Per Kjellander <perkj@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43460}
This commit is contained in:
parent
72b5769bb8
commit
e0a524b5e0
@ -46,7 +46,7 @@ class DataRate final : public rtc_units_impl::RelativeUnit<DataRate> {
|
||||
}
|
||||
static constexpr DataRate Infinity() { return PlusInfinity(); }
|
||||
|
||||
DataRate() = delete;
|
||||
constexpr DataRate() = default;
|
||||
|
||||
template <typename Sink>
|
||||
friend void AbslStringify(Sink& sink, DataRate value);
|
||||
|
||||
@ -34,6 +34,7 @@ TEST(DataRateTest, ConstExpr) {
|
||||
constexpr int64_t kValue = 12345;
|
||||
constexpr DataRate kDataRateZero = DataRate::Zero();
|
||||
constexpr DataRate kDataRateInf = DataRate::Infinity();
|
||||
static_assert(DataRate() == kDataRateZero);
|
||||
static_assert(kDataRateZero.IsZero(), "");
|
||||
static_assert(kDataRateInf.IsInfinite(), "");
|
||||
static_assert(kDataRateInf.bps_or(-1) == -1, "");
|
||||
|
||||
@ -29,7 +29,7 @@ class DataSize final : public rtc_units_impl::RelativeUnit<DataSize> {
|
||||
}
|
||||
static constexpr DataSize Infinity() { return PlusInfinity(); }
|
||||
|
||||
DataSize() = delete;
|
||||
constexpr DataSize() = default;
|
||||
|
||||
template <typename Sink>
|
||||
friend void AbslStringify(Sink& sink, DataSize value);
|
||||
|
||||
@ -22,6 +22,7 @@ TEST(DataSizeTest, ConstExpr) {
|
||||
constexpr int64_t kValue = 12345;
|
||||
constexpr DataSize kDataSizeZero = DataSize::Zero();
|
||||
constexpr DataSize kDataSizeInf = DataSize::Infinity();
|
||||
static_assert(DataSize() == kDataSizeZero);
|
||||
static_assert(kDataSizeZero.IsZero(), "");
|
||||
static_assert(kDataSizeInf.IsInfinite(), "");
|
||||
static_assert(kDataSizeInf.bytes_or(-1) == -1, "");
|
||||
|
||||
@ -41,7 +41,7 @@ class Frequency final : public rtc_units_impl::RelativeUnit<Frequency> {
|
||||
return FromFraction(1'000'000, value);
|
||||
}
|
||||
|
||||
Frequency() = delete;
|
||||
constexpr Frequency() = default;
|
||||
|
||||
template <typename Sink>
|
||||
friend void AbslStringify(Sink& sink, Frequency value);
|
||||
|
||||
@ -20,6 +20,7 @@ TEST(FrequencyTest, ConstExpr) {
|
||||
constexpr Frequency kFrequencyZero = Frequency::Zero();
|
||||
constexpr Frequency kFrequencyPlusInf = Frequency::PlusInfinity();
|
||||
constexpr Frequency kFrequencyMinusInf = Frequency::MinusInfinity();
|
||||
static_assert(Frequency() == kFrequencyZero);
|
||||
static_assert(kFrequencyZero.IsZero(), "");
|
||||
static_assert(kFrequencyPlusInf.IsPlusInfinity(), "");
|
||||
static_assert(kFrequencyMinusInf.IsMinusInfinity(), "");
|
||||
|
||||
@ -51,7 +51,7 @@ class TimeDelta final : public rtc_units_impl::RelativeUnit<TimeDelta> {
|
||||
return FromValue(value);
|
||||
}
|
||||
|
||||
TimeDelta() = delete;
|
||||
constexpr TimeDelta() = default;
|
||||
|
||||
template <typename Sink>
|
||||
friend void AbslStringify(Sink& sink, TimeDelta value);
|
||||
|
||||
@ -23,6 +23,7 @@ TEST(TimeDeltaTest, ConstExpr) {
|
||||
constexpr TimeDelta kTimeDeltaZero = TimeDelta::Zero();
|
||||
constexpr TimeDelta kTimeDeltaPlusInf = TimeDelta::PlusInfinity();
|
||||
constexpr TimeDelta kTimeDeltaMinusInf = TimeDelta::MinusInfinity();
|
||||
static_assert(TimeDelta() == kTimeDeltaZero);
|
||||
static_assert(kTimeDeltaZero.IsZero(), "");
|
||||
static_assert(kTimeDeltaPlusInf.IsPlusInfinity(), "");
|
||||
static_assert(kTimeDeltaMinusInf.IsMinusInfinity(), "");
|
||||
|
||||
@ -356,16 +356,8 @@ struct StreamDataCounters {
|
||||
};
|
||||
|
||||
class RtpSendRates {
|
||||
template <std::size_t... Is>
|
||||
constexpr std::array<DataRate, sizeof...(Is)> make_zero_array(
|
||||
std::index_sequence<Is...>) {
|
||||
return {{(static_cast<void>(Is), DataRate::Zero())...}};
|
||||
}
|
||||
|
||||
public:
|
||||
RtpSendRates()
|
||||
: send_rates_(
|
||||
make_zero_array(std::make_index_sequence<kNumMediaTypes>())) {}
|
||||
constexpr RtpSendRates() = default;
|
||||
RtpSendRates(const RtpSendRates& rhs) = default;
|
||||
RtpSendRates& operator=(const RtpSendRates&) = default;
|
||||
|
||||
|
||||
@ -275,6 +275,7 @@ class RelativeUnit : public UnitBase<Unit_T> {
|
||||
|
||||
protected:
|
||||
using UnitBase<Unit_T>::UnitBase;
|
||||
constexpr RelativeUnit() : UnitBase<Unit_T>(0) {}
|
||||
};
|
||||
|
||||
template <class Unit_T>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user