forked from mpusz/mp-units
refactor: QuantityLike concept improved
This commit is contained in:
@@ -261,6 +261,9 @@ inline constexpr bool is_quantity_kind = false;
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
inline constexpr bool is_quantity_point_kind = false;
|
inline constexpr bool is_quantity_point_kind = false;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline constexpr bool is_quantity_like = false;
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -304,12 +307,7 @@ concept QuantityPointKind = detail::is_quantity_point_kind<T>;
|
|||||||
* type trait is provided.
|
* type trait is provided.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept QuantityLike = requires(T q) {
|
concept QuantityLike = detail::is_quantity_like<T>;
|
||||||
typename quantity_like_traits<T>::dimension;
|
|
||||||
typename quantity_like_traits<T>::unit;
|
|
||||||
typename quantity_like_traits<T>::rep;
|
|
||||||
{ quantity_like_traits<T>::count(q) } -> std::convertible_to<typename quantity_like_traits<T>::rep>;
|
|
||||||
};
|
|
||||||
|
|
||||||
// QuantityValue
|
// QuantityValue
|
||||||
|
|
||||||
@@ -378,4 +376,20 @@ concept QuantityValue =
|
|||||||
std::regular<T> &&
|
std::regular<T> &&
|
||||||
scalable_<T>;
|
scalable_<T>;
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
requires requires(T q) {
|
||||||
|
typename quantity_like_traits<T>::dimension;
|
||||||
|
typename quantity_like_traits<T>::unit;
|
||||||
|
typename quantity_like_traits<T>::rep;
|
||||||
|
requires Dimension<typename quantity_like_traits<T>::dimension>;
|
||||||
|
requires Unit<typename quantity_like_traits<T>::unit>;
|
||||||
|
requires QuantityValue<typename quantity_like_traits<T>::rep>;
|
||||||
|
{ quantity_like_traits<T>::count(q) } -> std::convertible_to<typename quantity_like_traits<T>::rep>;
|
||||||
|
}
|
||||||
|
inline constexpr bool is_quantity_like<T> = true;
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
} // namespace units
|
} // namespace units
|
||||||
|
@@ -31,6 +31,7 @@ using namespace units::physical;
|
|||||||
using namespace units::physical::si::literals;
|
using namespace units::physical::si::literals;
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
static_assert(QuantityLike<std::chrono::seconds>);
|
||||||
|
|
||||||
// construction - same rep type
|
// construction - same rep type
|
||||||
static_assert(std::constructible_from<si::time<si::second, std::chrono::seconds::rep>, std::chrono::seconds>);
|
static_assert(std::constructible_from<si::time<si::second, std::chrono::seconds::rep>, std::chrono::seconds>);
|
||||||
|
Reference in New Issue
Block a user