refactor: number() and number_in() renamed to value() and value_in()
Resolves #423
This commit is contained in:
1 parent
ae92b49775
commit
a9204e2473
21 files changed
+349
-351
No files matched your search
@@ -51,9 +51,9 @@ template<QuantitySpec auto ToQS, typename Q>
|
||||
{
|
||||
if constexpr (detail::QuantityKindSpec<std::remove_const_t<decltype(ToQS)>> &&
|
||||
AssociatedUnit<std::remove_const_t<decltype(q.unit)>>)
|
||||
return make_quantity<q.unit>(std::forward<Q>(q).number());
|
||||
return make_quantity<q.unit>(std::forward<Q>(q).value());
|
||||
else
|
||||
return make_quantity<reference<ToQS, q.unit>{}>(std::forward<Q>(q).number());
|
||||
return make_quantity<reference<ToQS, q.unit>{}>(std::forward<Q>(q).value());
|
||||
}
|
||||
|
||||
} // namespace mp_units
|
||||
@@ -74,7 +74,7 @@ concept QuantityLike = requires(T q) {
|
||||
requires RepresentationOf<typename quantity_like_traits<T>::rep,
|
||||
get_quantity_spec(quantity_like_traits<T>::reference).character>;
|
||||
{
|
||||
quantity_like_traits<T>::number(q)
|
||||
quantity_like_traits<T>::value(q)
|
||||
} -> std::convertible_to<typename quantity_like_traits<T>::rep>;
|
||||
};
|
||||
|
||||
|
||||
@@ -63,10 +63,10 @@ template<Quantity To, typename From>
|
||||
if constexpr (q_unit == To::unit) {
|
||||
// no scaling of the number needed
|
||||
return make_quantity<To::reference>(static_cast<MP_UNITS_TYPENAME To::rep>(
|
||||
std::forward<From>(q).number())); // this is the only (and recommended) way to do
|
||||
// a truncating conversion on a number, so we are
|
||||
// using static_cast to suppress all the compiler
|
||||
// warnings on conversions
|
||||
std::forward<From>(q).value())); // this is the only (and recommended) way to do
|
||||
// a truncating conversion on a number, so we are
|
||||
// using static_cast to suppress all the compiler
|
||||
// warnings on conversions
|
||||
} else {
|
||||
// scale the number
|
||||
constexpr Magnitude auto c_mag = get_canonical_unit(q_unit).mag / get_canonical_unit(To::unit).mag;
|
||||
@@ -78,7 +78,7 @@ template<Quantity To, typename From>
|
||||
using multiplier_type =
|
||||
conditional<treat_as_floating_point<c_rep_type>, std::common_type_t<c_mag_type, long double>, c_mag_type>;
|
||||
constexpr auto val = [](Magnitude auto m) { return get_value<multiplier_type>(m); };
|
||||
return static_cast<MP_UNITS_TYPENAME To::rep>(static_cast<c_rep_type>(std::forward<From>(q).number()) * val(num) /
|
||||
return static_cast<MP_UNITS_TYPENAME To::rep>(static_cast<c_rep_type>(std::forward<From>(q).value()) * val(num) /
|
||||
val(den) * val(irr)) *
|
||||
To::reference;
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ struct quantity_values {
|
||||
* @brief Provides support for external quantity-like types
|
||||
*
|
||||
* The type trait should provide the @c reference object, a type alias @c rep,
|
||||
* and a static member function @c number(T) that returns the raw value of the quantity.
|
||||
* and a static member function @c value(T) that returns the raw value of the quantity.
|
||||
*
|
||||
* Usage example can be found in @c units/chrono.h header file.
|
||||
*
|
||||
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
|
||||
template<detail::QuantityConvertibleTo<quantity> Q>
|
||||
constexpr explicit(!std::convertible_to<typename Q::rep, Rep>) quantity(const Q& q) :
|
||||
number_(detail::sudo_cast<quantity>(q).number())
|
||||
number_(detail::sudo_cast<quantity>(q).value())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public:
|
||||
requires detail::QuantityConvertibleTo<
|
||||
quantity<quantity_like_traits<Q>::reference, typename quantity_like_traits<Q>::rep>, quantity>
|
||||
constexpr explicit quantity(const Q& q) :
|
||||
quantity(make_quantity<quantity_like_traits<Q>::reference>(quantity_like_traits<Q>::number(q)))
|
||||
quantity(make_quantity<quantity_like_traits<Q>::reference>(quantity_like_traits<Q>::value(q)))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -152,22 +152,22 @@ public:
|
||||
// data access
|
||||
#ifdef __cpp_explicit_this_parameter
|
||||
template<typename Self>
|
||||
[[nodiscard]] constexpr auto&& number(this Self&& self) noexcept
|
||||
[[nodiscard]] constexpr auto&& value(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_); }
|
||||
[[nodiscard]] constexpr rep& value() & noexcept { return number_; }
|
||||
[[nodiscard]] constexpr const rep& value() const& noexcept { return number_; }
|
||||
[[nodiscard]] constexpr rep&& value() && noexcept { return std::move(number_); }
|
||||
[[nodiscard]] constexpr const rep&& value() const&& noexcept { return std::move(number_); }
|
||||
#endif
|
||||
|
||||
template<Unit U>
|
||||
requires requires(quantity q) { q.in(U{}); }
|
||||
[[nodiscard]] constexpr rep number_in(U) const noexcept
|
||||
[[nodiscard]] constexpr rep value_in(U) const noexcept
|
||||
{
|
||||
return (*this).in(U{}).number();
|
||||
return (*this).in(U{}).value();
|
||||
}
|
||||
|
||||
template<Unit U>
|
||||
@@ -185,7 +185,7 @@ public:
|
||||
} -> std::common_with<rep>;
|
||||
}
|
||||
{
|
||||
return make_quantity<reference>(+number());
|
||||
return make_quantity<reference>(+value());
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Quantity auto operator-() const
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
} -> std::common_with<rep>;
|
||||
}
|
||||
{
|
||||
return make_quantity<reference>(-number());
|
||||
return make_quantity<reference>(-value());
|
||||
}
|
||||
|
||||
constexpr quantity& operator++()
|
||||
@@ -247,7 +247,7 @@ public:
|
||||
} -> std::same_as<rep&>;
|
||||
}
|
||||
{
|
||||
number_ += q.number();
|
||||
number_ += q.value();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ public:
|
||||
} -> std::same_as<rep&>;
|
||||
}
|
||||
{
|
||||
number_ -= q.number();
|
||||
number_ -= q.value();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ public:
|
||||
}
|
||||
constexpr quantity& operator*=(const Q& rhs)
|
||||
{
|
||||
number_ *= rhs.number();
|
||||
number_ *= rhs.value();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -307,8 +307,8 @@ public:
|
||||
}
|
||||
constexpr quantity& operator/=(const Q& rhs)
|
||||
{
|
||||
gsl_ExpectsAudit(rhs.number() != quantity_values<typename Q::rep>::zero());
|
||||
number_ /= rhs.number();
|
||||
gsl_ExpectsAudit(rhs.value() != quantity_values<typename Q::rep>::zero());
|
||||
number_ /= rhs.value();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -319,8 +319,8 @@ public:
|
||||
} -> std::same_as<rep&>;
|
||||
}
|
||||
{
|
||||
gsl_ExpectsAudit(q.number() != quantity_values<rep>::zero());
|
||||
number_ %= q.number();
|
||||
gsl_ExpectsAudit(q.value() != quantity_values<rep>::zero());
|
||||
number_ %= q.value();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity auto operator+(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
using ret = detail::common_quantity_for<std::plus<>, quantity<R1, Rep1>, quantity<R2, Rep2>>;
|
||||
return make_quantity<ret::reference>(ret(lhs).number() + ret(rhs).number());
|
||||
return make_quantity<ret::reference>(ret(lhs).value() + ret(rhs).value());
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
@@ -354,7 +354,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
[[nodiscard]] constexpr Quantity auto operator-(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
using ret = detail::common_quantity_for<std::minus<>, quantity<R1, Rep1>, quantity<R2, Rep2>>;
|
||||
return make_quantity<ret::reference>(ret(lhs).number() - ret(rhs).number());
|
||||
return make_quantity<ret::reference>(ret(lhs).value() - ret(rhs).value());
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
@@ -362,7 +362,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
Rep2>
|
||||
[[nodiscard]] constexpr Quantity auto operator*(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
return make_quantity<R1 * R2>(lhs.number() * rhs.number());
|
||||
return make_quantity<R1 * R2>(lhs.value() * rhs.value());
|
||||
}
|
||||
|
||||
template<auto R, typename Rep, typename Value>
|
||||
@@ -370,7 +370,7 @@ template<auto R, typename Rep, typename Value>
|
||||
detail::InvokeResultOf<get_quantity_spec(R).character, std::multiplies<>, Rep, const Value&>
|
||||
[[nodiscard]] constexpr Quantity auto operator*(const quantity<R, Rep>& q, const Value& v)
|
||||
{
|
||||
return make_quantity<R>(q.number() * v);
|
||||
return make_quantity<R>(q.value() * v);
|
||||
}
|
||||
|
||||
template<typename Value, auto R, typename Rep>
|
||||
@@ -378,15 +378,15 @@ template<typename Value, auto R, typename Rep>
|
||||
detail::InvokeResultOf<get_quantity_spec(R).character, std::multiplies<>, const Value&, Rep>
|
||||
[[nodiscard]] constexpr Quantity auto operator*(const Value& v, const quantity<R, Rep>& q)
|
||||
{
|
||||
return make_quantity<R>(v * q.number());
|
||||
return make_quantity<R>(v * q.value());
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
requires detail::InvokeResultOf<(get_quantity_spec(R1) / get_quantity_spec(R2)).character, std::divides<>, Rep1, Rep2>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
gsl_ExpectsAudit(rhs.number() != quantity_values<Rep2>::zero());
|
||||
return make_quantity<R1 / R2>(lhs.number() / rhs.number());
|
||||
gsl_ExpectsAudit(rhs.value() != quantity_values<Rep2>::zero());
|
||||
return make_quantity<R1 / R2>(lhs.value() / rhs.value());
|
||||
}
|
||||
|
||||
template<auto R, typename Rep, typename Value>
|
||||
@@ -395,7 +395,7 @@ template<auto R, typename Rep, typename Value>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const quantity<R, Rep>& q, const Value& v)
|
||||
{
|
||||
gsl_ExpectsAudit(v != quantity_values<Value>::zero());
|
||||
return make_quantity<R>(q.number() / v);
|
||||
return make_quantity<R>(q.value() / v);
|
||||
}
|
||||
|
||||
template<typename Value, auto R, typename Rep>
|
||||
@@ -403,7 +403,7 @@ template<typename Value, auto R, typename Rep>
|
||||
detail::InvokeResultOf<get_quantity_spec(R).character, std::divides<>, const Value&, Rep>
|
||||
[[nodiscard]] constexpr Quantity auto operator/(const Value& v, const quantity<R, Rep>& q)
|
||||
{
|
||||
return make_quantity<::mp_units::one / R>(v / q.number());
|
||||
return make_quantity<::mp_units::one / R>(v / q.value());
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
@@ -411,9 +411,9 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
detail::InvocableQuantities<std::modulus<>, quantity<R1, Rep1>, quantity<R2, Rep2>>
|
||||
[[nodiscard]] constexpr Quantity auto operator%(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
gsl_ExpectsAudit(rhs.number() != quantity_values<Rep1>::zero());
|
||||
gsl_ExpectsAudit(rhs.value() != quantity_values<Rep1>::zero());
|
||||
using ret = detail::common_quantity_for<std::modulus<>, quantity<R1, Rep1>, quantity<R2, Rep2>>;
|
||||
return make_quantity<ret::reference>(ret(lhs).number() % ret(rhs).number());
|
||||
return make_quantity<ret::reference>(ret(lhs).value() % ret(rhs).value());
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
@@ -422,7 +422,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
[[nodiscard]] constexpr bool operator==(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
using ct = std::common_type_t<quantity<R1, Rep1>, quantity<R2, Rep2>>;
|
||||
return ct(lhs).number() == ct(rhs).number();
|
||||
return ct(lhs).value() == ct(rhs).value();
|
||||
}
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
@@ -431,7 +431,7 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
[[nodiscard]] constexpr auto operator<=>(const quantity<R1, Rep1>& lhs, const quantity<R2, Rep2>& rhs)
|
||||
{
|
||||
using ct = std::common_type_t<quantity<R1, Rep1>, quantity<R2, Rep2>>;
|
||||
return ct(lhs).number() <=> ct(rhs).number();
|
||||
return ct(lhs).value() <=> ct(rhs).value();
|
||||
}
|
||||
|
||||
// make_quantity
|
||||
|
||||
@@ -115,7 +115,7 @@ struct quantity_spec_interface {
|
||||
requires Quantity<std::remove_cvref_t<Q>> &&
|
||||
(explicitly_convertible(std::remove_reference_t<Q>::quantity_spec, self))
|
||||
{
|
||||
return make_quantity<reference<self, std::remove_cvref_t<Q>::unit>{}>(std::forward<Q>(q).number());
|
||||
return make_quantity<reference<self, std::remove_cvref_t<Q>::unit>{}>(std::forward<Q>(q).value());
|
||||
}
|
||||
#else
|
||||
template<typename Self_ = Self, UnitOf<Self_{}> U>
|
||||
@@ -132,7 +132,7 @@ struct quantity_spec_interface {
|
||||
(explicitly_convertible(std::remove_reference_t<Q>::quantity_spec, Self_{}))
|
||||
[[nodiscard]] constexpr Quantity auto operator()(Q&& q) const
|
||||
{
|
||||
return make_quantity<reference<Self{}, std::remove_cvref_t<Q>::unit>{}>(std::forward<Q>(q).number());
|
||||
return make_quantity<reference<Self{}, std::remove_cvref_t<Q>::unit>{}>(std::forward<Q>(q).value());
|
||||
}
|
||||
#endif
|
||||
};
|
||||
@@ -311,7 +311,7 @@ struct quantity_spec<Self, QS, Args...> : std::remove_const_t<decltype(QS)> {
|
||||
(explicitly_convertible(std::remove_reference_t<Q>::quantity_spec, Self_{}))
|
||||
[[nodiscard]] constexpr Quantity auto operator()(Q&& q) const
|
||||
{
|
||||
return make_quantity<reference<Self{}, std::remove_cvref_t<Q>::unit>{}>(std::forward<Q>(q).number());
|
||||
return make_quantity<reference<Self{}, std::remove_cvref_t<Q>::unit>{}>(std::forward<Q>(q).value());
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user