mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 05:04:27 +02:00
feat: explicit this
interfaces added for getters in quantity
and quantity_point
This commit is contained in:
@@ -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{}]; }
|
||||||
|
@@ -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
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user