feat: explicit this interfaces added for getters in quantity and quantity_point

This commit is contained in:
Mateusz Pusz
2023-08-01 17:26:00 +02:00
parent 5015d7c3e3
commit 4c2e288017
2 changed files with 16 additions and 0 deletions

View File

@@ -151,10 +151,18 @@ public:
quantity& operator=(quantity&&) = default; quantity& operator=(quantity&&) = default;
// data access // data access
#ifdef __cpp_explicit_this_parameter
template<typename Self>
[[nodiscard]] constexpr auto&& number(this Self&& self) noexcept
{
return std::forward<Self>(self).number_;
}
#else
[[nodiscard]] constexpr rep& number() & noexcept { return number_; } [[nodiscard]] constexpr rep& number() & noexcept { return number_; }
[[nodiscard]] constexpr const rep& number() const& noexcept { return number_; } [[nodiscard]] constexpr const rep& number() const& noexcept { return number_; }
[[nodiscard]] constexpr rep&& number() && noexcept { return std::move(number_); } [[nodiscard]] constexpr rep&& number() && noexcept { return std::move(number_); }
[[nodiscard]] constexpr const rep&& number() const&& noexcept { return std::move(number_); } [[nodiscard]] constexpr const rep&& number() const&& noexcept { return std::move(number_); }
#endif
template<Unit U> template<Unit U>
requires requires(quantity q) { q[U{}]; } requires requires(quantity q) { q[U{}]; }

View File

@@ -140,10 +140,18 @@ public:
quantity_point& operator=(quantity_point&&) = default; quantity_point& operator=(quantity_point&&) = default;
// data access // data access
#ifdef __cpp_explicit_this_parameter
template<typename Self>
[[nodiscard]] constexpr auto&& relative(this Self&& self) noexcept
{
return std::forward<Self>(self).q_;
}
#else
[[nodiscard]] constexpr quantity_type& relative() & noexcept { return q_; } [[nodiscard]] constexpr quantity_type& relative() & noexcept { return q_; }
[[nodiscard]] constexpr const quantity_type& relative() const& noexcept { return q_; } [[nodiscard]] constexpr const quantity_type& relative() const& noexcept { return q_; }
[[nodiscard]] constexpr quantity_type&& relative() && noexcept { return std::move(q_); } [[nodiscard]] constexpr quantity_type&& relative() && noexcept { return std::move(q_); }
[[nodiscard]] constexpr const quantity_type&& relative() const&& noexcept { return std::move(q_); } [[nodiscard]] constexpr const quantity_type&& relative() const&& noexcept { return std::move(q_); }
#endif
[[nodiscard]] constexpr Quantity auto absolute() const noexcept [[nodiscard]] constexpr Quantity auto absolute() const noexcept
{ {