From 6dd07002c2058007f27d62628eaab6f442d2819b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 29 Sep 2018 18:19:25 -0700 Subject: [PATCH] Unit specific concepts introduced --- example/example.cpp | 6 +++--- src/include/units/si/frequency.h | 13 +++++++++++++ src/include/units/si/length.h | 13 +++++++++++++ src/include/units/si/time.h | 13 +++++++++++++ src/include/units/si/velocity.h | 13 +++++++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 2eb568b7..a29ebd1c 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -25,11 +25,11 @@ using namespace units; -template -void foo(velocity v, time t) +template + requires Velocity && Time +void foo(V v, T t) { const auto distance = v * t; - std::cout << "A car driving " << v.count() << " km/h in a time of " << t.count() << " minutes will pass " << quantity_cast>(distance).count() << " meters.\n"; } diff --git a/src/include/units/si/frequency.h b/src/include/units/si/frequency.h index ac7731fc..b7d972a5 100644 --- a/src/include/units/si/frequency.h +++ b/src/include/units/si/frequency.h @@ -39,6 +39,19 @@ namespace units { 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; + // ... namespace literals { diff --git a/src/include/units/si/length.h b/src/include/units/si/length.h index 150330df..9487657b 100644 --- a/src/include/units/si/length.h +++ b/src/include/units/si/length.h @@ -36,6 +36,19 @@ namespace units { 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; + namespace literals { // mm diff --git a/src/include/units/si/time.h b/src/include/units/si/time.h index d32c0160..de7f1955 100644 --- a/src/include/units/si/time.h +++ b/src/include/units/si/time.h @@ -39,6 +39,19 @@ namespace units { 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; + // ... namespace literals { diff --git a/src/include/units/si/velocity.h b/src/include/units/si/velocity.h index 6b6b917e..3d153b8e 100644 --- a/src/include/units/si/velocity.h +++ b/src/include/units/si/velocity.h @@ -37,6 +37,19 @@ namespace units { 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; + // ... namespace literals {