Concepts usage improved

This commit is contained in:
Mateusz Pusz
2018-11-10 17:10:30 -08:00
parent 94fd74000c
commit 297b71efcf
7 changed files with 18 additions and 61 deletions

View File

@@ -29,17 +29,13 @@ namespace mp {
namespace std_concepts { namespace std_concepts {
namespace detail { template<typename T, typename U>
template<class T, class U> concept bool Same = std::is_same_v<T, U>;
concept bool SameHelper = std::is_same_v<T, U>;
}
template<class T, class U> template<typename From, typename To>
concept bool Same = detail::SameHelper<T, U>&& detail::SameHelper<U, T>; concept bool ConvertibleTo =
std::is_convertible_v<From, To> &&
template<class From, class To> requires(From (&f)()) {
concept bool ConvertibleTo = std::is_convertible_v<From, To>&& requires(From (&f)())
{
static_cast<To>(f()); static_cast<To>(f());
}; };

View File

@@ -32,7 +32,7 @@ namespace units {
template<typename T> template<typename T>
concept bool Number = requires(T a, T b) { concept bool Number = requires(T a, T b) {
{ a + b} -> T; { a + b } -> T;
{ a - b } -> T; { a - b } -> T;
{ a * b } -> T; { a * b } -> T;
{ a / b } -> T; { a / b } -> T;

View File

@@ -48,7 +48,7 @@ namespace units {
// treat_as_floating_point // 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>; inline constexpr bool treat_as_floating_point = std::is_floating_point_v<Rep>;
// quantity_cast // quantity_cast

View File

@@ -36,21 +36,11 @@ namespace units {
using gigahertz = unit<dimension_frequency, std::giga>; using gigahertz = unit<dimension_frequency, std::giga>;
using terahertz = unit<dimension_frequency, std::tera>; 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>; using frequency = quantity<dimension_frequency, U, Rep>;
namespace detail {
template<typename T> template<typename T>
struct is_frequency : std::false_type {}; concept bool Frequency = Quantity<T> && Same<typename T::dimension, dimension_frequency>;
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;
// ... // ...

View File

@@ -34,21 +34,11 @@ namespace units {
using meter = unit<dimension_length, std::ratio<1>>; using meter = unit<dimension_length, std::ratio<1>>;
using kilometer = unit<dimension_length, std::kilo>; 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>; using length = quantity<dimension_length, U, Rep>;
namespace detail {
template<typename T> template<typename T>
struct is_length : std::false_type {}; concept bool Length = Quantity<T> && Same<typename T::dimension, dimension_length>;
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;
namespace literals { namespace literals {

View File

@@ -36,21 +36,12 @@ namespace units {
using minute = unit<dimension_time, std::ratio<60>>; using minute = unit<dimension_time, std::ratio<60>>;
using hour = unit<dimension_time, std::ratio<3600>>; 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>; using time = quantity<dimension_time, U, Rep>;
namespace detail {
template<typename T> template<typename T>
struct is_time : std::false_type {}; concept bool Time = Quantity<T> && Same<typename T::dimension, dimension_time>;
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;
// ... // ...

View File

@@ -34,21 +34,11 @@ namespace units {
using kilometer_per_hour = unit<dimension_velocity, std::ratio<1000, 3600>>; using kilometer_per_hour = unit<dimension_velocity, std::ratio<1000, 3600>>;
using mile_per_hour = unit<dimension_velocity, std::ratio<44'704, 100'000>>; 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>; using velocity = quantity<dimension_velocity, U, Rep>;
namespace detail {
template<typename T> template<typename T>
struct is_velocity : std::false_type {}; concept bool Velocity = Quantity<T> && Same<typename T::dimension, dimension_velocity>;
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;
// ... // ...