util/OptionalCounter: add operator+= and operator-=

This commit is contained in:
Max Kellermann 2022-11-10 15:57:51 +01:00
parent 5670d98c54
commit 78d8b5f73c

View File

@ -44,6 +44,8 @@ public:
constexpr void reset() noexcept {}
constexpr auto &operator++() noexcept { return *this; }
constexpr auto &operator--() noexcept { return *this; }
constexpr auto &operator+=(std::size_t) noexcept { return *this; }
constexpr auto &operator-=(std::size_t) noexcept { return *this; }
};
template<>
@ -71,4 +73,16 @@ public:
--value;
return *this;
}
constexpr auto &operator+=(std::size_t n) noexcept {
value += n;
return *this;
}
constexpr auto &operator-=(std::size_t n) noexcept {
assert(value >= n);
value -= n;
return *this;
}
};