mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-06 05:34:27 +02:00
refactor: QuantityLike
now requires value
to exactly return rep
This commit is contained in:
@@ -32,6 +32,10 @@ namespace mp_units {
|
|||||||
template<Reference auto R, RepresentationOf<get_quantity_spec(R).character> Rep>
|
template<Reference auto R, RepresentationOf<get_quantity_spec(R).character> Rep>
|
||||||
class quantity;
|
class quantity;
|
||||||
|
|
||||||
|
template<Reference auto R, typename Rep>
|
||||||
|
requires quantity<R, std::remove_cvref_t<Rep>>::_rep_safe_constructible_
|
||||||
|
[[nodiscard]] constexpr quantity<R, std::remove_cvref_t<Rep>> make_quantity(Rep&& v);
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template<auto R, typename Rep>
|
template<auto R, typename Rep>
|
||||||
@@ -74,8 +78,8 @@ concept QuantityLike = requires(T q) {
|
|||||||
requires RepresentationOf<typename quantity_like_traits<T>::rep,
|
requires RepresentationOf<typename quantity_like_traits<T>::rep,
|
||||||
get_quantity_spec(quantity_like_traits<T>::reference).character>;
|
get_quantity_spec(quantity_like_traits<T>::reference).character>;
|
||||||
{
|
{
|
||||||
quantity_like_traits<T>::value(q)
|
make_quantity<quantity_like_traits<T>::reference>(quantity_like_traits<T>::value(q))
|
||||||
} -> std::convertible_to<typename quantity_like_traits<T>::rep>;
|
} -> std::same_as<quantity<quantity_like_traits<T>::reference, typename quantity_like_traits<T>::rep>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mp_units
|
} // namespace mp_units
|
||||||
|
@@ -29,10 +29,6 @@
|
|||||||
|
|
||||||
namespace mp_units {
|
namespace mp_units {
|
||||||
|
|
||||||
template<Reference auto R, typename Rep>
|
|
||||||
requires quantity<R, std::remove_cvref_t<Rep>>::_rep_safe_constructible_
|
|
||||||
[[nodiscard]] constexpr quantity<R, std::remove_cvref_t<Rep>> make_quantity(Rep&& v);
|
|
||||||
|
|
||||||
[[nodiscard]] consteval QuantitySpec auto get_quantity_spec(AssociatedUnit auto u)
|
[[nodiscard]] consteval QuantitySpec auto get_quantity_spec(AssociatedUnit auto u)
|
||||||
{
|
{
|
||||||
return detail::get_associated_quantity(u);
|
return detail::get_associated_quantity(u);
|
||||||
|
@@ -80,7 +80,7 @@ struct quantity_point_like_traits<std::chrono::time_point<C, std::chrono::durati
|
|||||||
static constexpr auto reference = detail::time_unit_from_chrono_period<Period>();
|
static constexpr auto reference = detail::time_unit_from_chrono_period<Period>();
|
||||||
static constexpr auto point_origin = chrono_point_origin<C>;
|
static constexpr auto point_origin = chrono_point_origin<C>;
|
||||||
using rep = Rep;
|
using rep = Rep;
|
||||||
[[nodiscard]] static constexpr auto quantity_from_origin(
|
[[nodiscard]] static constexpr quantity<reference, rep> quantity_from_origin(
|
||||||
const std::chrono::time_point<C, std::chrono::duration<Rep, Period>>& qp)
|
const std::chrono::time_point<C, std::chrono::duration<Rep, Period>>& qp)
|
||||||
{
|
{
|
||||||
return quantity{qp.time_since_epoch()};
|
return quantity{qp.time_since_epoch()};
|
||||||
|
Reference in New Issue
Block a user