mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-06 13:44:27 +02:00
refactor: quantity_like
types refactored
This commit is contained in:
@@ -165,12 +165,11 @@ concept weak_quantity_of = Quantity<Q> &&
|
||||
|
||||
template<typename T>
|
||||
concept quantity_like = requires(T q) {
|
||||
quantity_like_traits<T>::dimension;
|
||||
quantity_like_traits<T>::unit;
|
||||
quantity_like_traits<T>::reference;
|
||||
typename quantity_like_traits<T>::rep;
|
||||
requires Dimension<std::remove_const_t<decltype(quantity_like_traits<T>::dimension)>>;
|
||||
requires Unit<std::remove_const_t<decltype(quantity_like_traits<T>::unit)>>;
|
||||
requires Representation<typename quantity_like_traits<T>::rep>;
|
||||
requires Reference<std::remove_const_t<decltype(quantity_like_traits<T>::reference)>>;
|
||||
requires RepresentationOf<typename quantity_like_traits<T>::rep,
|
||||
quantity_like_traits<T>::reference.quantity_spec.character>;
|
||||
{
|
||||
quantity_like_traits<T>::number(q)
|
||||
} -> std::convertible_to<typename quantity_like_traits<T>::rep>;
|
||||
|
@@ -129,8 +129,8 @@ struct quantity_values {
|
||||
/**
|
||||
* @brief Provides support for external quantity-like types
|
||||
*
|
||||
* The type trait should provide the following nested values @c dimension, @c unit and type alias @c rep,
|
||||
* and a static member function @c number(T) that will return the raw value of the quantity.
|
||||
* 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.
|
||||
*
|
||||
* Usage example can be found in @c units/chrono.h header file.
|
||||
*
|
||||
|
@@ -42,6 +42,9 @@ namespace detail {
|
||||
template<typename T>
|
||||
concept quantity_one = quantity_of<T, dimensionless[one]>;
|
||||
|
||||
template<quantity_like Q>
|
||||
using quantity_like_type = quantity<quantity_like_traits<Q>::reference, typename quantity_like_traits<Q>::rep>;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<typename T, typename Arg>
|
||||
@@ -64,10 +67,6 @@ template<quantity_character Ch, typename Func, typename T, typename U>
|
||||
concept invoke_result_of_ =
|
||||
std::regular_invocable<Func, T, U> && RepresentationOf<std::invoke_result_t<Func, T, U>, Ch>;
|
||||
|
||||
template<quantity_like Q>
|
||||
using quantity_like_type = quantity<reference<quantity_like_traits<Q>::dimension, quantity_like_traits<Q>::unit>{},
|
||||
typename quantity_like_traits<Q>::rep>;
|
||||
|
||||
/**
|
||||
* @brief A quantity
|
||||
*
|
||||
@@ -131,8 +130,8 @@ public:
|
||||
}
|
||||
|
||||
template<quantity_like Q>
|
||||
requires quantity_convertible_to_<quantity_like_type<Q>, quantity>
|
||||
constexpr explicit quantity(const Q& q) : quantity(quantity_like_type<Q>(quantity_like_traits<Q>::number(q)))
|
||||
requires quantity_convertible_to_<detail::quantity_like_type<Q>, quantity>
|
||||
constexpr explicit quantity(const Q& q): quantity(detail::quantity_like_type<Q>(quantity_like_traits<Q>::number(q)))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -452,8 +451,7 @@ explicit(false) quantity(Rep&&) -> quantity<R, Rep>;
|
||||
#endif
|
||||
|
||||
template<quantity_like Q>
|
||||
explicit quantity(Q) -> quantity<reference<quantity_like_traits<Q>::dimension, quantity_like_traits<Q>::unit>{},
|
||||
typename quantity_like_traits<Q>::rep>;
|
||||
explicit quantity(Q) -> quantity<quantity_like_traits<Q>::reference, typename quantity_like_traits<Q>::rep>;
|
||||
|
||||
// non-member binary operators
|
||||
template<Quantity Q1, Quantity Q2>
|
||||
|
Reference in New Issue
Block a user