Makes all units and operations constexpr
Since RTC_DCHECK was made constexpr compatible, we can now make the unit classes fully constexpr. Bug: webrtc:9883 Change-Id: I18973c2f318449869cf0bd45699c41be53fba806 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167722 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Ali Tofigh <alito@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30403}
This commit is contained in:
committed by
Commit Bot
parent
48be482d73
commit
d7fade5738
@ -43,6 +43,10 @@ class TestUnit final : public rtc_units_impl::RelativeUnit<TestUnit> {
|
||||
static constexpr bool one_sided = false;
|
||||
using RelativeUnit<TestUnit>::RelativeUnit;
|
||||
};
|
||||
constexpr TestUnit TestUnitAddKilo(TestUnit value, int add_kilo) {
|
||||
value += TestUnit::FromKilo(add_kilo);
|
||||
return value;
|
||||
}
|
||||
} // namespace
|
||||
namespace test {
|
||||
TEST(UnitBaseTest, ConstExpr) {
|
||||
@ -62,6 +66,8 @@ TEST(UnitBaseTest, ConstExpr) {
|
||||
|
||||
static_assert(kTestUnitKilo.ToKiloOr(0) == kValue, "");
|
||||
static_assert(kTestUnitValue.ToValueOr(0) == kValue, "");
|
||||
static_assert(TestUnitAddKilo(kTestUnitValue, 2).ToValue() == kValue + 2000,
|
||||
"");
|
||||
}
|
||||
|
||||
TEST(UnitBaseTest, GetBackSameValues) {
|
||||
|
||||
Reference in New Issue
Block a user