From 297b71efcfdda2d878dbc958932083ed5c0a2296 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 10 Nov 2018 17:10:30 -0800 Subject: [PATCH] Concepts usage improved --- src/include/units/bits/stdconcepts.h | 20 ++++++++------------ src/include/units/bits/tools.h | 2 +- src/include/units/quantity.h | 2 +- src/include/units/si/frequency.h | 14 ++------------ src/include/units/si/length.h | 14 ++------------ src/include/units/si/time.h | 13 ++----------- src/include/units/si/velocity.h | 14 ++------------ 7 files changed, 18 insertions(+), 61 deletions(-) diff --git a/src/include/units/bits/stdconcepts.h b/src/include/units/bits/stdconcepts.h index 12ff750e..7a60a0e5 100644 --- a/src/include/units/bits/stdconcepts.h +++ b/src/include/units/bits/stdconcepts.h @@ -29,19 +29,15 @@ namespace mp { namespace std_concepts { - namespace detail { - template - concept bool SameHelper = std::is_same_v; - } + template + concept bool Same = std::is_same_v; - template - concept bool Same = detail::SameHelper&& detail::SameHelper; - - template - concept bool ConvertibleTo = std::is_convertible_v&& requires(From (&f)()) - { - static_cast(f()); - }; + template + concept bool ConvertibleTo = + std::is_convertible_v && + requires(From (&f)()) { + static_cast(f()); + }; } // namespace std_concepts } // namespace mp diff --git a/src/include/units/bits/tools.h b/src/include/units/bits/tools.h index 516ca3ff..3bf4e09e 100644 --- a/src/include/units/bits/tools.h +++ b/src/include/units/bits/tools.h @@ -32,7 +32,7 @@ namespace units { template concept bool Number = requires(T a, T b) { - { a + b} -> T; + { a + b } -> T; { a - b } -> T; { a * b } -> T; { a / b } -> T; diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index c8b3cd54..9f7a0448 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -48,7 +48,7 @@ namespace units { // treat_as_floating_point - template + template // todo Conceptify that inline constexpr bool treat_as_floating_point = std::is_floating_point_v; // quantity_cast diff --git a/src/include/units/si/frequency.h b/src/include/units/si/frequency.h index b7d972a5..0d27b3a1 100644 --- a/src/include/units/si/frequency.h +++ b/src/include/units/si/frequency.h @@ -36,21 +36,11 @@ namespace units { using gigahertz = unit; using terahertz = unit; - template + template using frequency = quantity; - namespace detail { - - template - struct is_frequency : std::false_type {}; - - template - struct is_frequency> : std::true_type {}; - - } - template - concept bool Frequency = detail::is_frequency::value; + concept bool Frequency = Quantity && Same; // ... diff --git a/src/include/units/si/length.h b/src/include/units/si/length.h index e4ce39e6..de31b55c 100644 --- a/src/include/units/si/length.h +++ b/src/include/units/si/length.h @@ -34,21 +34,11 @@ namespace units { using meter = unit>; using kilometer = unit; - template + template using length = quantity; - namespace detail { - - template - struct is_length : std::false_type {}; - - template - struct is_length> : std::true_type {}; - - } - template - concept bool Length = detail::is_length::value; + concept bool Length = Quantity && Same; namespace literals { diff --git a/src/include/units/si/time.h b/src/include/units/si/time.h index de7f1955..41ec3353 100644 --- a/src/include/units/si/time.h +++ b/src/include/units/si/time.h @@ -36,21 +36,12 @@ namespace units { using minute = unit>; using hour = unit>; - template + template using time = quantity; - namespace detail { - - template - struct is_time : std::false_type {}; - - template - struct is_time> : std::true_type {}; - - } template - concept bool Time = detail::is_time::value; + concept bool Time = Quantity && Same; // ... diff --git a/src/include/units/si/velocity.h b/src/include/units/si/velocity.h index 3d153b8e..adb6ca67 100644 --- a/src/include/units/si/velocity.h +++ b/src/include/units/si/velocity.h @@ -34,21 +34,11 @@ namespace units { using kilometer_per_hour = unit>; using mile_per_hour = unit>; - template + template using velocity = quantity; - namespace detail { - - template - struct is_velocity : std::false_type {}; - - template - struct is_velocity> : std::true_type {}; - - } - template - concept bool Velocity = detail::is_velocity::value; + concept bool Velocity = Quantity && Same; // ...