From 78d8b5f73c309ab16ae1941ba5c949a74ccbc2fd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 10 Nov 2022 15:57:51 +0100 Subject: [PATCH] util/OptionalCounter: add operator+= and operator-= --- src/util/OptionalCounter.hxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util/OptionalCounter.hxx b/src/util/OptionalCounter.hxx index ad4a43988..f00e846b3 100644 --- a/src/util/OptionalCounter.hxx +++ b/src/util/OptionalCounter.hxx @@ -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; + } };