From da64f1789583f7b2a32ce04e12731f6c1e123758 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 3 Jan 2023 17:44:44 +0100 Subject: [PATCH] feat: `quantity::number_in(Unit auto)` added + removed non-const lvalue overload of `number()` Resolves #412 --- src/core/include/mp_units/quantity.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/core/include/mp_units/quantity.h b/src/core/include/mp_units/quantity.h index 11700992..07267b79 100644 --- a/src/core/include/mp_units/quantity.h +++ b/src/core/include/mp_units/quantity.h @@ -139,18 +139,16 @@ public: quantity& operator=(quantity&&) = default; // data access -#ifdef __cpp_explicit_this_parameter - template - [[nodiscard]] constexpr auto&& number(this Self&& self) noexcept - { - return std::forward(self).number_; - } -#else - [[nodiscard]] constexpr rep& number() & noexcept { return number_; } [[nodiscard]] constexpr const rep& number() const& noexcept { return number_; } [[nodiscard]] constexpr rep&& number() && noexcept { return std::move(number_); } [[nodiscard]] constexpr const rep&& number() const&& noexcept { return std::move(number_); } -#endif + + template + requires requires(quantity q) { q[U{}]; } + [[nodiscard]] constexpr rep number_in(U) const noexcept + { + return (*this)[U{}].number(); + } template requires quantity_convertible_to_{}, Rep>>