forked from mpusz/mp-units
Concepts usage improved
This commit is contained in:
@@ -29,17 +29,13 @@ namespace mp {
|
||||
|
||||
namespace std_concepts {
|
||||
|
||||
namespace detail {
|
||||
template<class T, class U>
|
||||
concept bool SameHelper = std::is_same_v<T, U>;
|
||||
}
|
||||
template<typename T, typename U>
|
||||
concept bool Same = std::is_same_v<T, U>;
|
||||
|
||||
template<class T, class U>
|
||||
concept bool Same = detail::SameHelper<T, U>&& detail::SameHelper<U, T>;
|
||||
|
||||
template<class From, class To>
|
||||
concept bool ConvertibleTo = std::is_convertible_v<From, To>&& requires(From (&f)())
|
||||
{
|
||||
template<typename From, typename To>
|
||||
concept bool ConvertibleTo =
|
||||
std::is_convertible_v<From, To> &&
|
||||
requires(From (&f)()) {
|
||||
static_cast<To>(f());
|
||||
};
|
||||
|
||||
|
@@ -48,7 +48,7 @@ namespace units {
|
||||
|
||||
// treat_as_floating_point
|
||||
|
||||
template<class Rep>
|
||||
template<typename Rep> // todo Conceptify that
|
||||
inline constexpr bool treat_as_floating_point = std::is_floating_point_v<Rep>;
|
||||
|
||||
// quantity_cast
|
||||
|
@@ -36,21 +36,11 @@ namespace units {
|
||||
using gigahertz = unit<dimension_frequency, std::giga>;
|
||||
using terahertz = unit<dimension_frequency, std::tera>;
|
||||
|
||||
template<Unit U = hertz, typename Rep = std::intmax_t>
|
||||
template<Unit U = hertz, Number Rep = std::intmax_t>
|
||||
using frequency = quantity<dimension_frequency, U, Rep>;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
struct is_frequency : std::false_type {};
|
||||
|
||||
template<Unit U, typename Rep>
|
||||
struct is_frequency<frequency<U, Rep>> : std::true_type {};
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
concept bool Frequency = detail::is_frequency<T>::value;
|
||||
concept bool Frequency = Quantity<T> && Same<typename T::dimension, dimension_frequency>;
|
||||
|
||||
// ...
|
||||
|
||||
|
@@ -34,21 +34,11 @@ namespace units {
|
||||
using meter = unit<dimension_length, std::ratio<1>>;
|
||||
using kilometer = unit<dimension_length, std::kilo>;
|
||||
|
||||
template<Unit U = meter, typename Rep = std::intmax_t>
|
||||
template<Unit U = meter, Number Rep = std::intmax_t>
|
||||
using length = quantity<dimension_length, U, Rep>;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
struct is_length : std::false_type {};
|
||||
|
||||
template<Unit U, typename Rep>
|
||||
struct is_length<length<U, Rep>> : std::true_type {};
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
concept bool Length = detail::is_length<T>::value;
|
||||
concept bool Length = Quantity<T> && Same<typename T::dimension, dimension_length>;
|
||||
|
||||
namespace literals {
|
||||
|
||||
|
@@ -36,21 +36,12 @@ namespace units {
|
||||
using minute = unit<dimension_time, std::ratio<60>>;
|
||||
using hour = unit<dimension_time, std::ratio<3600>>;
|
||||
|
||||
template<Unit U = second, typename Rep = std::intmax_t>
|
||||
template<Unit U = second, Number Rep = std::intmax_t>
|
||||
using time = quantity<dimension_time, U, Rep>;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
struct is_time : std::false_type {};
|
||||
|
||||
template<Unit U, typename Rep>
|
||||
struct is_time<time<U, Rep>> : std::true_type {};
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
concept bool Time = detail::is_time<T>::value;
|
||||
concept bool Time = Quantity<T> && Same<typename T::dimension, dimension_time>;
|
||||
|
||||
// ...
|
||||
|
||||
|
@@ -34,21 +34,11 @@ namespace units {
|
||||
using kilometer_per_hour = unit<dimension_velocity, std::ratio<1000, 3600>>;
|
||||
using mile_per_hour = unit<dimension_velocity, std::ratio<44'704, 100'000>>;
|
||||
|
||||
template<Unit U = meter_per_second, typename Rep = std::intmax_t>
|
||||
template<Unit U = meter_per_second, Number Rep = std::intmax_t>
|
||||
using velocity = quantity<dimension_velocity, U, Rep>;
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
struct is_velocity : std::false_type {};
|
||||
|
||||
template<Unit U, typename Rep>
|
||||
struct is_velocity<velocity<U, Rep>> : std::true_type {};
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
concept bool Velocity = detail::is_velocity<T>::value;
|
||||
concept bool Velocity = Quantity<T> && Same<typename T::dimension, dimension_velocity>;
|
||||
|
||||
// ...
|
||||
|
||||
|
Reference in New Issue
Block a user