Skip to content

Commit

Permalink
feat: explicit this interfaces added for getters in quantity and …
Browse files Browse the repository at this point in the history
…`quantity_point`
  • Loading branch information
mpusz committed Aug 1, 2023
1 parent 5015d7c commit 4c2e288
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/include/mp-units/quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,18 @@ class quantity {
quantity& operator=(quantity&&) = default;

// 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 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<Unit U>
requires requires(quantity q) { q[U{}]; }
Expand Down
8 changes: 8 additions & 0 deletions src/core/include/mp-units/quantity_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,18 @@ class quantity_point {
quantity_point& operator=(quantity_point&&) = default;

// 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 const quantity_type& relative() const& noexcept { return q_; }
[[nodiscard]] constexpr quantity_type&& relative() && 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
{
Expand Down

0 comments on commit 4c2e288

Please sign in to comment.