mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-30 18:37:15 +02:00
gcc-10 enabled
This commit is contained in:
@ -28,7 +28,7 @@ namespace {
|
|||||||
using namespace units::literals;
|
using namespace units::literals;
|
||||||
|
|
||||||
template<units::Length D, units::Time T>
|
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;
|
return d / t;
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ constexpr units::Velocity avg_speed(D d, T t)
|
|||||||
template<units::Velocity V, units::Time T>
|
template<units::Velocity V, units::Time T>
|
||||||
void example_1(V v, T 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 "
|
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";
|
<< units::quantity_cast<units::quantity<units::metre, double>>(distance).count() << " metres.\n";
|
||||||
}
|
}
|
||||||
|
@ -63,12 +63,17 @@ target_include_directories(units
|
|||||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||||
target_compile_options(units
|
target_compile_options(units
|
||||||
INTERFACE
|
INTERFACE
|
||||||
-fconcepts
|
|
||||||
-Wno-literal-suffix
|
-Wno-literal-suffix
|
||||||
-Wno-non-template-friend
|
-Wno-non-template-friend
|
||||||
# TODO gcc:92101
|
# TODO gcc:92101
|
||||||
-Wno-pedantic
|
-Wno-pedantic
|
||||||
)
|
)
|
||||||
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
|
||||||
|
target_compile_options(units
|
||||||
|
INTERFACE
|
||||||
|
-fconcepts
|
||||||
|
)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
add_library(mp::units ALIAS units)
|
add_library(mp::units ALIAS units)
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
namespace units {
|
namespace units {
|
||||||
|
|
||||||
|
#if __GNUC__ < 10
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept Number = std::regular<T> &&
|
concept Number = std::regular<T> &&
|
||||||
std::totally_ordered<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
|
} // namespace units
|
||||||
|
@ -31,6 +31,12 @@
|
|||||||
#define Expects(cond) assert(cond);
|
#define Expects(cond) assert(cond);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __GNUC__ > 9
|
||||||
|
#define AUTO auto
|
||||||
|
#else
|
||||||
|
#define AUTO
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
||||||
// concepts
|
// concepts
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
namespace units {
|
namespace units {
|
||||||
|
|
||||||
template<std::size_t N, typename U, typename Rep>
|
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 dim = dimension_pow<typename U::dimension, N>;
|
||||||
using r = ratio_pow<typename U::ratio, N>;
|
using r = ratio_pow<typename U::ratio, N>;
|
||||||
@ -36,7 +36,7 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename Rep>
|
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 dim = dimension_sqrt<typename U::dimension>;
|
||||||
using r = ratio_sqrt<typename U::ratio>;
|
using r = ratio_sqrt<typename U::ratio>;
|
||||||
|
@ -307,7 +307,7 @@ namespace units {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename U1, typename Rep1, typename U2, typename Rep2>
|
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>
|
requires same_dim<typename U1::dimension, typename U2::dimension>
|
||||||
{
|
{
|
||||||
using common_rep = decltype(lhs.count() + rhs.count());
|
using common_rep = decltype(lhs.count() + rhs.count());
|
||||||
@ -316,7 +316,7 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U1, typename Rep1, typename U2, typename Rep2>
|
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>
|
requires same_dim<typename U1::dimension, typename U2::dimension>
|
||||||
{
|
{
|
||||||
using common_rep = decltype(lhs.count() - rhs.count());
|
using common_rep = decltype(lhs.count() - rhs.count());
|
||||||
@ -325,7 +325,7 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename Rep1, Scalar Rep2>
|
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>)
|
requires (!Quantity<Rep2>)
|
||||||
{
|
{
|
||||||
using common_rep = decltype(q.count() * v);
|
using common_rep = decltype(q.count() * v);
|
||||||
@ -334,14 +334,14 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<Scalar Rep1, typename U, typename Rep2>
|
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>)
|
requires (!Quantity<Rep1>)
|
||||||
{
|
{
|
||||||
return q * v;
|
return q * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename U1, typename Rep1, typename U2, typename Rep2>
|
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>>
|
requires same_dim<typename U1::dimension, dim_invert<typename U2::dimension>>
|
||||||
{
|
{
|
||||||
using common_rep = decltype(lhs.count() * rhs.count());
|
using common_rep = decltype(lhs.count() * rhs.count());
|
||||||
@ -350,7 +350,7 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U1, typename Rep1, typename U2, typename Rep2>
|
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>>) &&
|
requires (!same_dim<typename U1::dimension, dim_invert<typename U2::dimension>>) &&
|
||||||
(treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
|
(treat_as_floating_point<decltype(lhs.count() * rhs.count())> ||
|
||||||
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1))
|
(std::ratio_multiply<typename U1::ratio, typename U2::ratio>::den == 1))
|
||||||
@ -362,7 +362,7 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<Scalar Rep1, typename U, typename Rep2>
|
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>)
|
requires (!Quantity<Rep1>)
|
||||||
{
|
{
|
||||||
Expects(q != std::remove_cvref_t<decltype(q)>(0));
|
Expects(q != std::remove_cvref_t<decltype(q)>(0));
|
||||||
@ -375,7 +375,7 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename Rep1, Scalar Rep2>
|
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>)
|
requires (!Quantity<Rep2>)
|
||||||
{
|
{
|
||||||
Expects(v != Rep2{0});
|
Expects(v != Rep2{0});
|
||||||
@ -386,7 +386,7 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U1, typename Rep1, typename U2, typename Rep2>
|
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>
|
requires same_dim<typename U1::dimension, typename U2::dimension>
|
||||||
{
|
{
|
||||||
Expects(rhs != std::remove_cvref_t<decltype(rhs)>(0));
|
Expects(rhs != std::remove_cvref_t<decltype(rhs)>(0));
|
||||||
@ -397,7 +397,7 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U1, typename Rep1, typename U2, typename Rep2>
|
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>) &&
|
requires (!same_dim<typename U1::dimension, typename U2::dimension>) &&
|
||||||
(treat_as_floating_point<decltype(lhs.count() / rhs.count())> ||
|
(treat_as_floating_point<decltype(lhs.count() / rhs.count())> ||
|
||||||
(ratio_divide<typename U1::ratio, typename U2::ratio>::den == 1))
|
(ratio_divide<typename U1::ratio, typename U2::ratio>::den == 1))
|
||||||
@ -411,7 +411,7 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U, typename Rep1, Scalar Rep2>
|
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 common_rep = decltype(q.count() % v);
|
||||||
using ret = quantity<U, common_rep>;
|
using ret = quantity<U, common_rep>;
|
||||||
@ -419,7 +419,7 @@ namespace units {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename U1, typename Rep1, typename U2, typename Rep2>
|
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 common_rep = decltype(lhs.count() % rhs.count());
|
||||||
using ret = common_quantity<quantity<U1, Rep1>, quantity<U2, Rep2>, common_rep>;
|
using ret = common_quantity<quantity<U1, Rep1>, quantity<U2, Rep2>, common_rep>;
|
||||||
|
Reference in New Issue
Block a user