From 95028d10a72ff88afdd6123ebd527fac12ee0ff0 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Thu, 17 Oct 2019 18:22:51 +0200 Subject: [PATCH] gcc-10 enabled --- example/example.cpp | 4 ++-- src/CMakeLists.txt | 7 ++++++- src/include/units/bits/concepts.h | 26 ++++++++++++++++++++++++++ src/include/units/bits/hacks.h | 6 ++++++ src/include/units/math.h | 4 ++-- src/include/units/quantity.h | 24 ++++++++++++------------ 6 files changed, 54 insertions(+), 17 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index a4424a7d..c5c1b03d 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -28,7 +28,7 @@ namespace { using namespace units::literals; template -constexpr units::Velocity avg_speed(D d, T t) +constexpr units::Velocity AUTO avg_speed(D d, T t) { return d / t; } @@ -36,7 +36,7 @@ constexpr units::Velocity avg_speed(D d, T t) template void example_1(V v, T t) { - const units::Length distance = v * t; + const units::Length AUTO distance = v * t; std::cout << "A car driving " << v.count() << " km/h in a time of " << t.count() << " minutes will pass " << units::quantity_cast>(distance).count() << " metres.\n"; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4c04161c..09c9c3bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,12 +63,17 @@ target_include_directories(units if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) target_compile_options(units INTERFACE - -fconcepts -Wno-literal-suffix -Wno-non-template-friend # TODO gcc:92101 -Wno-pedantic ) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) + target_compile_options(units + INTERFACE + -fconcepts + ) + endif() endif() add_library(mp::units ALIAS units) diff --git a/src/include/units/bits/concepts.h b/src/include/units/bits/concepts.h index aaba6331..bf41edc4 100644 --- a/src/include/units/bits/concepts.h +++ b/src/include/units/bits/concepts.h @@ -26,6 +26,8 @@ namespace units { +#if __GNUC__ < 10 + template concept Number = std::regular && std::totally_ordered && @@ -44,4 +46,28 @@ namespace units { // … }; +#else + + template + concept Number = std::regular && + std::totally_ordered && + requires(T a, T b) { + { a + b } -> std::same_as; + { a - b } -> std::same_as; + { a * b } -> std::same_as; + { a / b } -> std::same_as; + { +a } -> std::same_as; + { -a } -> std::same_as; + { a += b } -> std::same_as; + { a -= b } -> std::same_as; + { a *= b } -> std::same_as; + { a /= b } -> std::same_as; + { T{0} }; // can construct a T from a zero + // … + }; + +#endif + + // InstanceOf + } // namespace units diff --git a/src/include/units/bits/hacks.h b/src/include/units/bits/hacks.h index 31ed51bd..a587601b 100644 --- a/src/include/units/bits/hacks.h +++ b/src/include/units/bits/hacks.h @@ -31,6 +31,12 @@ #define Expects(cond) assert(cond); #endif +#if __GNUC__ > 9 +#define AUTO auto +#else +#define AUTO +#endif + namespace std { // concepts diff --git a/src/include/units/math.h b/src/include/units/math.h index 46628653..f9e0d289 100644 --- a/src/include/units/math.h +++ b/src/include/units/math.h @@ -28,7 +28,7 @@ namespace units { template - inline Quantity pow(const quantity& q) noexcept + inline Quantity AUTO pow(const quantity& q) noexcept { using dim = dimension_pow; using r = ratio_pow; @@ -36,7 +36,7 @@ namespace units { } template - inline Quantity sqrt(const quantity& q) noexcept + inline Quantity AUTO sqrt(const quantity& q) noexcept { using dim = dimension_sqrt; using r = ratio_sqrt; diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index ff2a86a9..380bd911 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -307,7 +307,7 @@ namespace units { }; template - [[nodiscard]] constexpr Quantity operator+(const quantity& lhs, const quantity& rhs) + [[nodiscard]] constexpr Quantity AUTO operator+(const quantity& lhs, const quantity& rhs) requires same_dim { using common_rep = decltype(lhs.count() + rhs.count()); @@ -316,7 +316,7 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator-(const quantity& lhs, const quantity& rhs) + [[nodiscard]] constexpr Quantity AUTO operator-(const quantity& lhs, const quantity& rhs) requires same_dim { using common_rep = decltype(lhs.count() - rhs.count()); @@ -325,7 +325,7 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator*(const quantity& q, const Rep2& v) + [[nodiscard]] constexpr Quantity AUTO operator*(const quantity& q, const Rep2& v) requires (!Quantity) { using common_rep = decltype(q.count() * v); @@ -334,14 +334,14 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator*(const Rep1& v, const quantity& q) + [[nodiscard]] constexpr Quantity AUTO operator*(const Rep1& v, const quantity& q) requires (!Quantity) { return q * v; } template - [[nodiscard]] constexpr Scalar operator*(const quantity& lhs, const quantity& rhs) + [[nodiscard]] constexpr Scalar AUTO operator*(const quantity& lhs, const quantity& rhs) requires same_dim> { using common_rep = decltype(lhs.count() * rhs.count()); @@ -350,7 +350,7 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator*(const quantity& lhs, const quantity& rhs) + [[nodiscard]] constexpr Quantity AUTO operator*(const quantity& lhs, const quantity& rhs) requires (!same_dim>) && (treat_as_floating_point || (std::ratio_multiply::den == 1)) @@ -362,7 +362,7 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator/(const Rep1& v, const quantity& q) + [[nodiscard]] constexpr Quantity AUTO operator/(const Rep1& v, const quantity& q) requires (!Quantity) { Expects(q != std::remove_cvref_t(0)); @@ -375,7 +375,7 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator/(const quantity& q, const Rep2& v) + [[nodiscard]] constexpr Quantity AUTO operator/(const quantity& q, const Rep2& v) requires (!Quantity) { Expects(v != Rep2{0}); @@ -386,7 +386,7 @@ namespace units { } template - [[nodiscard]] constexpr Scalar operator/(const quantity& lhs, const quantity& rhs) + [[nodiscard]] constexpr Scalar AUTO operator/(const quantity& lhs, const quantity& rhs) requires same_dim { Expects(rhs != std::remove_cvref_t(0)); @@ -397,7 +397,7 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator/(const quantity& lhs, const quantity& rhs) + [[nodiscard]] constexpr Quantity AUTO operator/(const quantity& lhs, const quantity& rhs) requires (!same_dim) && (treat_as_floating_point || (ratio_divide::den == 1)) @@ -411,7 +411,7 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator%(const quantity& q, const Rep2& v) + [[nodiscard]] constexpr Quantity AUTO operator%(const quantity& q, const Rep2& v) { using common_rep = decltype(q.count() % v); using ret = quantity; @@ -419,7 +419,7 @@ namespace units { } template - [[nodiscard]] constexpr Quantity operator%(const quantity& lhs, const quantity& rhs) + [[nodiscard]] constexpr Quantity AUTO operator%(const quantity& lhs, const quantity& rhs) { using common_rep = decltype(lhs.count() % rhs.count()); using ret = common_quantity, quantity, common_rep>;