gcc-10 enabled

This commit is contained in:
Mateusz Pusz
2019-10-17 18:22:51 +02:00
parent f147da202e
commit 95028d10a7
6 changed files with 54 additions and 17 deletions

View File

@ -28,7 +28,7 @@ namespace {
using namespace units::literals;
template<units::Length D, units::Time T>
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<units::Velocity V, units::Time T>
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<units::quantity<units::metre, double>>(distance).count() << " metres.\n";
}

View File

@ -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)

View File

@ -26,6 +26,8 @@
namespace units {
#if __GNUC__ < 10
template<typename T>
concept Number = std::regular<T> &&
std::totally_ordered<T> &&
@ -44,4 +46,28 @@ namespace units {
// …
};
#else
template<typename T>
concept Number = std::regular<T> &&
std::totally_ordered<T> &&
requires(T a, T b) {
{ a + b } -> std::same_as<T>;
{ a - b } -> std::same_as<T>;
{ a * b } -> std::same_as<T>;
{ a / b } -> std::same_as<T>;
{ +a } -> std::same_as<T>;
{ -a } -> std::same_as<T>;
{ a += b } -> std::same_as<T&>;
{ a -= b } -> std::same_as<T&>;
{ a *= b } -> std::same_as<T&>;
{ a /= b } -> std::same_as<T&>;
{ T{0} }; // can construct a T from a zero
// …
};
#endif
// InstanceOf
} // namespace units

View File

@ -31,6 +31,12 @@
#define Expects(cond) assert(cond);
#endif
#if __GNUC__ > 9
#define AUTO auto
#else
#define AUTO
#endif
namespace std {
// concepts

View File

@ -28,7 +28,7 @@
namespace units {
template<std::size_t N, typename U, typename Rep>
inline Quantity pow(const quantity<U, Rep>& q) noexcept
inline Quantity AUTO pow(const quantity<U, Rep>& q) noexcept
{
using dim = dimension_pow<typename U::dimension, N>;
using r = ratio_pow<typename U::ratio, N>;
@ -36,7 +36,7 @@ namespace units {
}
template<typename U, typename Rep>
inline Quantity sqrt(const quantity<U, Rep>& q) noexcept
inline Quantity AUTO sqrt(const quantity<U, Rep>& q) noexcept
{
using dim = dimension_sqrt<typename U::dimension>;
using r = ratio_sqrt<typename U::ratio>;

View File

@ -307,7 +307,7 @@ namespace units {
};
template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Quantity operator+(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
[[nodiscard]] constexpr Quantity AUTO operator+(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
requires same_dim<typename U1::dimension, typename U2::dimension>
{
using common_rep = decltype(lhs.count() + rhs.count());
@ -316,7 +316,7 @@ namespace units {
}
template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Quantity operator-(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
[[nodiscard]] constexpr Quantity AUTO operator-(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
requires same_dim<typename U1::dimension, typename U2::dimension>
{
using common_rep = decltype(lhs.count() - rhs.count());
@ -325,7 +325,7 @@ namespace units {
}
template<typename U, typename Rep1, Scalar Rep2>
[[nodiscard]] constexpr Quantity operator*(const quantity<U, Rep1>& q, const Rep2& v)
[[nodiscard]] constexpr Quantity AUTO operator*(const quantity<U, Rep1>& q, const Rep2& v)
requires (!Quantity<Rep2>)
{
using common_rep = decltype(q.count() * v);
@ -334,14 +334,14 @@ namespace units {
}
template<Scalar Rep1, typename U, typename Rep2>
[[nodiscard]] constexpr Quantity operator*(const Rep1& v, const quantity<U, Rep2>& q)
[[nodiscard]] constexpr Quantity AUTO operator*(const Rep1& v, const quantity<U, Rep2>& q)
requires (!Quantity<Rep1>)
{
return q * v;
}
template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Scalar operator*(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
[[nodiscard]] constexpr Scalar AUTO operator*(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
requires same_dim<typename U1::dimension, dim_invert<typename U2::dimension>>
{
using common_rep = decltype(lhs.count() * rhs.count());
@ -350,7 +350,7 @@ namespace units {
}
template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Quantity operator*(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
[[nodiscard]] constexpr Quantity AUTO operator*(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
requires (!same_dim<typename U1::dimension, dim_invert<typename U2::dimension>>) &&
(treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1))
@ -362,7 +362,7 @@ namespace units {
}
template<Scalar Rep1, typename U, typename Rep2>
[[nodiscard]] constexpr Quantity operator/(const Rep1& v, const quantity<U, Rep2>& q)
[[nodiscard]] constexpr Quantity AUTO operator/(const Rep1& v, const quantity<U, Rep2>& q)
requires (!Quantity<Rep1>)
{
Expects(q != std::remove_cvref_t<decltype(q)>(0));
@ -375,7 +375,7 @@ namespace units {
}
template<typename U, typename Rep1, Scalar Rep2>
[[nodiscard]] constexpr Quantity operator/(const quantity<U, Rep1>& q, const Rep2& v)
[[nodiscard]] constexpr Quantity AUTO operator/(const quantity<U, Rep1>& q, const Rep2& v)
requires (!Quantity<Rep2>)
{
Expects(v != Rep2{0});
@ -386,7 +386,7 @@ namespace units {
}
template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Scalar operator/(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
[[nodiscard]] constexpr Scalar AUTO operator/(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
requires same_dim<typename U1::dimension, typename U2::dimension>
{
Expects(rhs != std::remove_cvref_t<decltype(rhs)>(0));
@ -397,7 +397,7 @@ namespace units {
}
template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Quantity operator/(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
[[nodiscard]] constexpr Quantity AUTO operator/(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
requires (!same_dim<typename U1::dimension, typename U2::dimension>) &&
(treat_as_floating_point<decltype(lhs.count() / rhs.count())> ||
(ratio_divide<typename U1::ratio, typename U2::ratio>::den == 1))
@ -411,7 +411,7 @@ namespace units {
}
template<typename U, typename Rep1, Scalar Rep2>
[[nodiscard]] constexpr Quantity operator%(const quantity<U, Rep1>& q, const Rep2& v)
[[nodiscard]] constexpr Quantity AUTO operator%(const quantity<U, Rep1>& q, const Rep2& v)
{
using common_rep = decltype(q.count() % v);
using ret = quantity<U, common_rep>;
@ -419,7 +419,7 @@ namespace units {
}
template<typename U1, typename Rep1, typename U2, typename Rep2>
[[nodiscard]] constexpr Quantity operator%(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
[[nodiscard]] constexpr Quantity AUTO operator%(const quantity<U1, Rep1>& lhs, const quantity<U2, Rep2>& rhs)
{
using common_rep = decltype(lhs.count() % rhs.count());
using ret = common_quantity<quantity<U1, Rep1>, quantity<U2, Rep2>, common_rep>;