refactor: got rid of gcc-9 backlog

BREAKING CHANGE: gcc-9.3 no longer supported
This commit is contained in:
Mateusz Pusz
2020-09-08 13:09:34 +02:00
parent 7ed4f19ef3
commit 4bb51586dc
27 changed files with 131 additions and 760 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
#include <units/physical/si/prefixes.h>
#include <units/quantity.h>
// get at the units text of the quantity, without its numeric value
inline auto constexpr units_str(const units::Quantity AUTO& q)
inline auto constexpr units_str(const units::Quantity auto& q)
{
typedef std::remove_cvref_t<decltype(q)> qtype;
return units::detail::unit_text<typename qtype::dimension, typename qtype::unit>();
+8 -8
View File
@@ -44,13 +44,13 @@ fixed_double_si_avg_speed(si::length<si::metre> d,
}
template<typename U1, typename R1, typename U2, typename R2>
constexpr Speed AUTO si_avg_speed(si::length<U1, R1> d,
constexpr Speed auto si_avg_speed(si::length<U1, R1> d,
si::time<U2, R2> t)
{
return d / t;
}
constexpr Speed AUTO avg_speed(Length AUTO d, Time AUTO t)
constexpr Speed auto avg_speed(Length auto d, Time auto t)
{
return d / t;
}
@@ -68,7 +68,7 @@ void example()
// SI (int)
{
using namespace units::physical::si::literals;
constexpr Length AUTO distance = 220q_km; // constructed from a UDL
constexpr Length auto distance = 220q_km; // constructed from a UDL
constexpr si::time<si::hour, int> duration(2); // constructed from a value
std::cout << "SI units with 'int' as representation\n";
@@ -82,7 +82,7 @@ void example()
// SI (double)
{
using namespace units::physical::si::literals;
constexpr Length AUTO distance = 220.q_km; // constructed from a UDL
constexpr Length auto distance = 220.q_km; // constructed from a UDL
constexpr si::time<si::hour> duration(2); // constructed from a value
std::cout << "\nSI units with 'double' as representation\n";
@@ -98,7 +98,7 @@ void example()
// Customary Units (int)
{
using namespace units::physical::international::literals;
constexpr Length AUTO distance = 140q_mi; // constructed from a UDL
constexpr Length auto distance = 140q_mi; // constructed from a UDL
constexpr si::time<si::hour, int> duration(2); // constructed from a value
std::cout << "\nUS Customary Units with 'int' as representation\n";
@@ -114,7 +114,7 @@ void example()
// Customary Units (double)
{
using namespace units::physical::international::literals;
constexpr Length AUTO distance = 140.q_mi; // constructed from a UDL
constexpr Length auto distance = 140.q_mi; // constructed from a UDL
constexpr si::time<si::hour> duration(2); // constructed from a value
std::cout << "\nUS Customary Units with 'double' as representation\n";
@@ -132,7 +132,7 @@ void example()
// CGS (int)
{
using namespace units::physical::cgs::literals;
constexpr Length AUTO distance = 22'000'000q_cm; // constructed from a UDL
constexpr Length auto distance = 22'000'000q_cm; // constructed from a UDL
constexpr cgs::time<si::hour, int> duration(2); // constructed from a value
std::cout << "\nCGS units with 'int' as representation\n";
@@ -151,7 +151,7 @@ void example()
// CGS (double)
{
using namespace units::physical::cgs::literals;
constexpr Length AUTO distance = 22'000'000.q_cm; // constructed from a UDL
constexpr Length auto distance = 22'000'000.q_cm; // constructed from a UDL
constexpr cgs::time<si::hour> duration(2); // constructed from a value
std::cout << "\nCGS units with 'double' as representation\n";
+1 -1
View File
@@ -41,7 +41,7 @@ int main()
constexpr auto R = 4.7q_kR;
for (auto t = 0q_ms; t <= 50q_ms; ++t) {
const Voltage AUTO Vt = V0 * units::exp(-t / (R * C));
const Voltage auto Vt = V0 * units::exp(-t / (R * C));
std::cout << "at " << t << " voltage is ";
+1 -1
View File
@@ -34,7 +34,7 @@ int main()
auto torque = 20.0q_Nm;
auto energy = 20.0q_J;
physical::Angle AUTO angle = torque / energy;
physical::Angle auto angle = torque / energy;
std::cout << angle << '\n';
}
+8 -61
View File
@@ -27,10 +27,7 @@
#include <units/quantity_point.h>
#include <array>
#include <iostream>
#if COMP_MSVC || COMP_GCC >= 10
#include <compare>
#endif
// horizontal/vertical vector
namespace {
@@ -59,10 +56,8 @@ public:
constexpr Q magnitude() const { return magnitude_; }
template<typename QQ = Q>
[[nodiscard]] constexpr vector operator-() const
requires requires(QQ q) { -q; }
// requires requires { -magnitude(); } // TODO gated by gcc-9 (fixed in gcc-10)
requires requires { -magnitude(); }
{
return vector(-magnitude());
}
@@ -92,15 +87,17 @@ public:
}
template<typename V>
requires (Scalar<V> || Dimensionless<V>)
[[nodiscard]] friend constexpr auto operator*(const vector& lhs, const V& value)
requires (Scalar<V> || Dimensionless<V>) && requires { lhs.magnitude() * value; }
requires requires { lhs.magnitude() * value; }
{
return vector<Q, D>(lhs.magnitude() * value);
}
template<typename V>
requires (Scalar<V> || Dimensionless<V>)
[[nodiscard]] friend constexpr auto operator*(const V& value, const vector& rhs)
requires (Scalar<V> || Dimensionless<V>) && requires { value * rhs.magnitude(); }
requires requires { value * rhs.magnitude(); }
{
return vector<Q, D>(value * rhs.magnitude());
}
@@ -112,8 +109,6 @@ public:
return lhs.magnitude() / rhs.magnitude();
}
#if COMP_MSVC || COMP_GCC >= 10
template<typename Q2>
[[nodiscard]] friend constexpr auto operator<=>(const vector& lhs, const vector<Q2, D>& rhs)
requires requires { lhs.magnitude() <=> rhs.magnitude(); }
@@ -128,56 +123,8 @@ public:
return lhs.magnitude() == rhs.magnitude();
}
#else
template<typename Q2>
[[nodiscard]] friend constexpr auto operator==(const vector& lhs, const vector<Q2, D>& rhs)
requires requires { lhs.magnitude() == rhs.magnitude(); }
{
return lhs.magnitude() == rhs.magnitude();
}
template<typename Q2>
[[nodiscard]] friend constexpr auto operator!=(const vector& lhs, const vector<Q2, D>& rhs)
requires requires { lhs.magnitude() != rhs.magnitude(); }
{
return !(lhs == rhs);
}
template<typename Q2>
[[nodiscard]] friend constexpr auto operator<(const vector& lhs, const vector<Q2, D>& rhs)
requires requires { lhs.magnitude() < rhs.magnitude(); }
{
return lhs.magnitude() < rhs.magnitude();
}
template<typename Q2>
[[nodiscard]] friend constexpr auto operator>(const vector& lhs, const vector<Q2, D>& rhs)
requires requires { lhs.magnitude() > rhs.magnitude(); }
{
return rhs < lhs;
}
template<typename Q2>
[[nodiscard]] friend constexpr auto operator<=(const vector& lhs, const vector<Q2, D>& rhs)
requires requires { lhs.magnitude() <= rhs.magnitude(); }
{
return !(rhs < lhs);
}
template<typename Q2>
[[nodiscard]] friend constexpr auto operator>=(const vector& lhs, const vector<Q2, D>& rhs)
requires requires { lhs.magnitude() >= rhs.magnitude(); }
{
return !(lhs < rhs);
}
#endif
// template<class CharT, class Traits>
// requires Quantity<Q> // TODO gated by gcc-9 (fixed in gcc-10)
template<class CharT, class Traits, typename QQ = Q>
requires Quantity<QQ>
template<class CharT, class Traits>
requires Quantity<Q>
friend std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const vector& v)
{
return os << v.magnitude();
@@ -278,7 +225,7 @@ auto get_gliders()
return gliders;
}
constexpr Dimensionless AUTO glide_ratio(const glider::polar_point& polar)
constexpr Dimensionless auto glide_ratio(const glider::polar_point& polar)
{
return polar.v / -polar.climb;
}
+5 -5
View File
@@ -27,7 +27,7 @@
using namespace units::physical;
constexpr Speed AUTO avg_speed(Length AUTO d, Time AUTO t)
constexpr Speed auto avg_speed(Length auto d, Time auto t)
{
return d / t;
}
@@ -35,10 +35,10 @@ constexpr Speed AUTO avg_speed(Length AUTO d, Time AUTO t)
int main()
{
using namespace units::physical::si::literals;
Speed AUTO v1 = avg_speed(220q_km, 2q_h);
Speed AUTO v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Speed AUTO v3 = quantity_cast<si::metre_per_second>(v2);
Speed AUTO v4 = quantity_cast<int>(v3);
Speed auto v1 = avg_speed(220q_km, 2q_h);
Speed auto v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Speed auto v3 = quantity_cast<si::metre_per_second>(v2);
Speed auto v4 = quantity_cast<int>(v3);
std::cout << v1 << '\n'; // 110 km/h
std::cout << fmt::format("{}", v2) << '\n'; // 70 mi/h
+2 -38
View File
@@ -22,11 +22,8 @@
#include <units/physical/si/acceleration.h>
#include <cmath>
#include <iostream>
#if COMP_MSVC || COMP_GCC >= 10
#include <compare>
#endif
#include <iostream>
namespace {
@@ -105,41 +102,8 @@ public:
return measurement(val, val * rhs.relative_uncertainty());
}
#if COMP_MSVC || COMP_GCC >= 10
[[nodiscard]] constexpr auto operator<=>(const measurement&) const = default;
#else
[[nodiscard]] friend constexpr bool operator==(const measurement& lhs, const measurement& rhs)
{
return lhs.value() == rhs.value() && lhs.uncertainty() == rhs.uncertainty();
}
[[nodiscard]] friend constexpr bool operator!=(const measurement& lhs, const measurement& rhs)
{
return !(lhs == rhs);
}
[[nodiscard]] friend constexpr bool operator<(const measurement& lhs, const measurement& rhs)
{
return lhs.value() == rhs.value() ? lhs.uncertainty() < rhs.uncertainty() : lhs.value() < rhs.value();
}
[[nodiscard]] friend constexpr bool operator>(const measurement& lhs, const measurement& rhs) { return rhs < lhs; }
[[nodiscard]] friend constexpr bool operator<=(const measurement& lhs, const measurement& rhs)
{
return !(rhs < lhs);
}
[[nodiscard]] friend constexpr bool operator>=(const measurement& lhs, const measurement& rhs)
{
return !(lhs < rhs);
}
#endif
friend std::ostream& operator<<(std::ostream& os, const measurement& v)
{
return os << v.value() << " ± " << v.uncertainty();
@@ -166,7 +130,7 @@ void example()
const auto a = si::acceleration<si::metre_per_second_sq, measurement<double>>(measurement(9.8, 0.1));
const auto t = si::time<si::second, measurement<double>>(measurement(1.2, 0.1));
const Speed AUTO v1 = a * t;
const Speed auto v1 = a * t;
std::cout << a << " * " << t << " = " << v1 << " = " << quantity_cast<si::kilometre_per_hour>(v1) << '\n';
si::length<si::metre, measurement<double>> length(measurement(123., 1.));
+7 -7
View File
@@ -32,7 +32,7 @@ namespace {
using namespace units::physical;
Energy AUTO total_energy(Momentum AUTO p, Mass AUTO m, Speed AUTO c)
Energy auto total_energy(Momentum auto p, Mass auto m, Speed auto c)
{
return sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c)));
}
@@ -42,13 +42,13 @@ void si_example()
using namespace units::physical::si;
using GeV = gigaelectronvolt;
constexpr Speed AUTO c = si2019::speed_of_light<>;
constexpr Speed auto c = si2019::speed_of_light<>;
std::cout << "\n*** SI units (c = " << c << ") ***\n";
const Momentum AUTO p = 4.q_GeV / c;
const Mass AUTO m = 3.q_GeV / pow<2>(c);
const Energy AUTO E = total_energy(p, m, c);
const Momentum auto p = 4.q_GeV / c;
const Mass auto m = 3.q_GeV / pow<2>(c);
const Energy auto E = total_energy(p, m, c);
std::cout << "[in GeV]\n"
<< "p = " << p << "\n"
@@ -73,10 +73,10 @@ void natural_example()
using namespace units::physical::natural;
using GeV = gigaelectronvolt;
constexpr Speed AUTO c = speed_of_light<>;
constexpr Speed auto c = speed_of_light<>;
const momentum<GeV> p(4);
const mass<GeV> m(3);
const Energy AUTO E = total_energy(p, m, c);
const Energy auto E = total_energy(p, m, c);
std::cout << "\n*** Natural units (c = " << c << ") ***\n"
<< "p = " << p << "\n"
+6 -6
View File
@@ -26,7 +26,7 @@
namespace {
template<units::physical::Length D, units::physical::Time T>
constexpr units::physical::Speed AUTO avg_speed(D d, T t)
constexpr units::physical::Speed auto avg_speed(D d, T t)
{
return d / t;
}
@@ -36,13 +36,13 @@ void example()
using namespace units::physical;
using namespace units::physical::si::literals;
Length AUTO d1 = 123q_m;
Time AUTO t1 = 10q_s;
Speed AUTO v1 = avg_speed(d1, t1);
Length auto d1 = 123q_m;
Time auto t1 = 10q_s;
Speed auto v1 = avg_speed(d1, t1);
auto temp1 = v1 * 50q_m; // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
Speed AUTO v2 = temp1 / 100q_m; // back to known dimensions again
Length AUTO d2 = v2 * 60q_s;
Speed auto v2 = temp1 / 100q_m; // back to known dimensions again
Length auto d2 = v2 * 60q_s;
std::cout << "d1 = " << d1 << '\n';
std::cout << "t1 = " << t1 << '\n';