mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-01 03:14:29 +02:00
Revert "Merge branch 'master-msvc-194-only-lib' into master-msvc-194"
This reverts commite3034c5554
, reversing changes made to8be458b0b7
.
This commit is contained in:
@@ -45,26 +45,26 @@ namespace {
|
||||
|
||||
using namespace mp_units;
|
||||
|
||||
constexpr quantity<si::metre / si::second, int> fixed_int_si_avg_speed(quantity<si::metre, int> d,
|
||||
quantity<si::second, int> t)
|
||||
constexpr quantity<si::metre / si::second, int> fixed_int_si_avg_speed(quantity<(si::metre), int> d,
|
||||
quantity<(si::second), int> t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
constexpr quantity<si::metre / si::second> fixed_double_si_avg_speed(quantity<si::metre> d, quantity<si::second> t)
|
||||
constexpr quantity<si::metre / si::second> fixed_double_si_avg_speed(quantity<(si::metre)> d, quantity<(si::second)> t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
constexpr QuantityOf<isq::speed> auto avg_speed(QuantityOf<isq::length> auto d, QuantityOf<isq::time> auto t)
|
||||
constexpr QuantityOf<(isq::speed)> auto avg_speed(QuantityOf<(isq::length)> auto d, QuantityOf<(isq::time)> auto t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
template<QuantityOf<isq::length> D, QuantityOf<isq::time> T, QuantityOf<isq::speed> V>
|
||||
template<QuantityOf<(isq::length)> D, QuantityOf<(isq::time)> T, QuantityOf<(isq::speed)> V>
|
||||
void print_result(D distance, T duration, V speed)
|
||||
{
|
||||
const auto result_in_kmph = speed.force_in(si::kilo<si::metre> / non_si::hour);
|
||||
const auto result_in_kmph = speed.force_in((si::kilo<(si::metre)> / non_si::hour));
|
||||
std::cout << "Average speed of a car that makes " << distance << " in " << duration << " is " << result_in_kmph
|
||||
<< ".\n";
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@ int main()
|
||||
constexpr auto RR = isq::resistance(4.7 * si::kilo<si::ohm>);
|
||||
|
||||
for (auto tt = 0 * ms; tt <= 50 * ms; ++tt) {
|
||||
const QuantityOf<isq::voltage> auto Vt = V0 * exp(dimensionless(-tt / (RR * CC)));
|
||||
const QuantityOf<(isq::voltage)> auto Vt = V0 * exp(dimensionless(-tt / (RR * CC)));
|
||||
// TODO try to make the below work instead
|
||||
// const QuantityOf<isq::voltage> auto Vt = V0 * exp(-tt / (RR * CC));
|
||||
|
||||
|
@@ -44,8 +44,8 @@ void simple_quantities()
|
||||
using namespace mp_units::si;
|
||||
using namespace mp_units::international;
|
||||
|
||||
using distance = quantity<isq::distance[kilo<metre>]>;
|
||||
using duration = quantity<isq::duration[second]>;
|
||||
using distance = quantity<(isq::distance[kilo<metre>])>;
|
||||
using duration = quantity<(isq::duration[second])>;
|
||||
|
||||
constexpr distance km = 1. * kilo<metre>;
|
||||
constexpr distance miles = 1. * mile;
|
||||
|
@@ -90,11 +90,11 @@ template<Unit auto From, Unit auto To>
|
||||
|
||||
#endif
|
||||
|
||||
template<ReferenceOf<currency> auto To, ReferenceOf<currency> auto From, typename Rep>
|
||||
quantity<To, Rep> exchange_to(quantity<From, Rep> q)
|
||||
{
|
||||
return static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * q.numerical_value()) * To;
|
||||
}
|
||||
// template<ReferenceOf<currency> auto To, ReferenceOf<currency> auto From, typename Rep>
|
||||
// quantity<To, Rep> exchange_to(quantity<From, Rep> q)
|
||||
// {
|
||||
// return static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * q.numerical_value()) * To;
|
||||
// }
|
||||
|
||||
template<ReferenceOf<currency> auto To, ReferenceOf<currency> auto From, auto PO, typename Rep>
|
||||
quantity_point<To, PO, Rep> exchange_to(quantity_point<From, PO, Rep> q)
|
||||
@@ -107,8 +107,8 @@ int main()
|
||||
{
|
||||
using namespace unit_symbols;
|
||||
|
||||
const quantity_point price_usd{100 * USD};
|
||||
const quantity_point price_euro = exchange_to<euro>(price_usd);
|
||||
const mp_units::quantity_point price_usd{100 * USD};
|
||||
const mp_units::quantity_point<euro, default_point_origin(euro), int> price_euro = exchange_to<euro>(price_usd);
|
||||
|
||||
std::cout << price_usd.quantity_from_zero() << " -> " << price_euro.quantity_from_zero() << "\n";
|
||||
// std::cout << price_usd.quantity_from_zero() + price_euro.quantity_from_zero() << "\n"; // does
|
||||
|
@@ -169,7 +169,7 @@ void example()
|
||||
const auto gliders = get_gliders();
|
||||
const auto waypoints = get_waypoints();
|
||||
const auto weather_conditions = get_weather_conditions();
|
||||
const task t = {waypoints[0], waypoints[1], waypoints[0]};
|
||||
const task glider_task = {waypoints[0], waypoints[1], waypoints[0]};
|
||||
const aircraft_tow tow = {400 * m, 1.6 * m / s};
|
||||
const timestamp start_time(std::chrono::system_clock::now());
|
||||
|
||||
@@ -177,16 +177,16 @@ void example()
|
||||
print(gliders);
|
||||
print(waypoints);
|
||||
print(weather_conditions);
|
||||
print(t);
|
||||
print(glider_task);
|
||||
print(tow);
|
||||
|
||||
for (const auto& g : gliders) {
|
||||
for (const auto& glider : gliders) {
|
||||
for (const auto& c : weather_conditions) {
|
||||
const std::string txt = "Scenario: Glider = " + g.name + ", Weather = " + c.first;
|
||||
const std::string txt = "Scenario: Glider = " + glider.name + ", Weather = " + c.first;
|
||||
std::cout << txt << "\n";
|
||||
std::cout << MP_UNITS_STD_FMT::format("{0:=^{1}}\n\n", "", txt.size());
|
||||
|
||||
estimate(start_time, g, c.second, t, sfty, tow);
|
||||
estimate(start_time, glider, c.second, glider_task, sfty, tow);
|
||||
|
||||
std::cout << "\n\n";
|
||||
}
|
||||
|
@@ -90,7 +90,7 @@ struct glider {
|
||||
std::array<polar_point, 1> polar;
|
||||
};
|
||||
|
||||
constexpr mp_units::QuantityOf<mp_units::dimensionless> auto glide_ratio(const glider::polar_point& polar)
|
||||
constexpr mp_units::QuantityOf<(mp_units::dimensionless)> auto glide_ratio(const glider::polar_point& polar)
|
||||
{
|
||||
return polar.v / -polar.climb;
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ import mp_units;
|
||||
|
||||
using namespace mp_units;
|
||||
|
||||
constexpr QuantityOf<isq::speed> auto avg_speed(QuantityOf<isq::length> auto d, QuantityOf<isq::time> auto t)
|
||||
constexpr QuantityOf<(isq::speed)> auto avg_speed(QuantityOf<(isq::length)> auto d, QuantityOf<(isq::time)> auto t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
@@ -79,10 +79,10 @@ inline constexpr struct prime_meridian final : mp_units::absolute_point_origin<m
|
||||
|
||||
|
||||
template<typename T = double>
|
||||
using latitude = mp_units::quantity_point<mp_units::si::degree, equator, ranged_representation<T, -90, 90>>;
|
||||
using latitude = mp_units::quantity_point<(mp_units::si::degree), equator, ranged_representation<T, -90, 90>>;
|
||||
|
||||
template<typename T = double>
|
||||
using longitude = mp_units::quantity_point<mp_units::si::degree, prime_meridian, ranged_representation<T, -180, 180>>;
|
||||
using longitude = mp_units::quantity_point<(mp_units::si::degree), prime_meridian, ranged_representation<T, -180, 180>>;
|
||||
|
||||
template<class CharT, class Traits, typename T>
|
||||
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const latitude<T>& lat)
|
||||
@@ -176,7 +176,7 @@ template<typename T>
|
||||
distance spherical_distance(position<T> from, position<T> to)
|
||||
{
|
||||
using namespace mp_units;
|
||||
constexpr quantity earth_radius = 6'371 * isq::radius[si::kilo<si::metre>];
|
||||
constexpr quantity earth_radius = 6'371 * isq::radius[si::kilo<(si::metre)>];
|
||||
|
||||
using si::sin, si::cos, si::asin, si::acos;
|
||||
|
||||
@@ -193,7 +193,7 @@ distance spherical_distance(position<T> from, position<T> to)
|
||||
// const auto central_angle = 2 * asin(sqrt(0.5 - cos(to_lat - from_lat) / 2 + cos(from_lat) * cos(to_lat) * (1
|
||||
// - cos(lon2_rad - from_lon)) / 2));
|
||||
|
||||
return quantity_cast<isq::distance>(earth_radius * central_angle);
|
||||
return quantity_cast<(isq::distance)>(earth_radius * central_angle);
|
||||
} else {
|
||||
// the haversine formula
|
||||
const quantity sin_lat = sin((to_lat - from_lat) / 2);
|
||||
|
@@ -116,15 +116,15 @@ template<mp_units::Quantity Q1, mp_units::Quantity Q2>
|
||||
}
|
||||
|
||||
// state update
|
||||
template<typename QP, mp_units::QuantityPoint QM, mp_units::QuantityOf<mp_units::dimensionless> K>
|
||||
template<typename QP, mp_units::QuantityPoint QM, mp_units::QuantityOf<(mp_units::dimensionless)> K>
|
||||
requires(implicitly_convertible(QM::quantity_spec, QP::quantity_spec))
|
||||
[[nodiscard]] constexpr system_state<QP> state_update(const system_state<QP>& predicted, QM measured, K gain)
|
||||
{
|
||||
return system_state<QP>{get<0>(predicted) + gain * (measured - get<0>(predicted))};
|
||||
}
|
||||
|
||||
template<typename QP1, typename QP2, mp_units::QuantityPoint QM, mp_units::QuantityOf<mp_units::dimensionless> K,
|
||||
mp_units::QuantityOf<mp_units::isq::time> T>
|
||||
template<typename QP1, typename QP2, mp_units::QuantityPoint QM, mp_units::QuantityOf<(mp_units::dimensionless)> K,
|
||||
mp_units::QuantityOf<(mp_units::isq::time)> T>
|
||||
requires(implicitly_convertible(QM::quantity_spec, QP1::quantity_spec))
|
||||
[[nodiscard]] constexpr system_state<QP1, QP2> state_update(const system_state<QP1, QP2>& predicted, QM measured,
|
||||
std::array<K, 2> gain, T interval)
|
||||
@@ -135,7 +135,7 @@ template<typename QP1, typename QP2, mp_units::QuantityPoint QM, mp_units::Quant
|
||||
}
|
||||
|
||||
template<typename QP1, typename QP2, typename QP3, mp_units::QuantityPoint QM,
|
||||
mp_units::QuantityOf<mp_units::dimensionless> K, mp_units::QuantityOf<mp_units::isq::time> T>
|
||||
mp_units::QuantityOf<(mp_units::dimensionless)> K, mp_units::QuantityOf<(mp_units::isq::time)> T>
|
||||
requires(implicitly_convertible(QM::quantity_spec, QP1::quantity_spec))
|
||||
[[nodiscard]] constexpr system_state<QP1, QP2, QP3> state_update(const system_state<QP1, QP2, QP3>& predicted,
|
||||
QM measured, std::array<K, 3> gain, T interval)
|
||||
@@ -147,13 +147,13 @@ template<typename QP1, typename QP2, typename QP3, mp_units::QuantityPoint QM,
|
||||
}
|
||||
|
||||
// covariance update
|
||||
template<mp_units::Quantity Q, mp_units::QuantityOf<mp_units::dimensionless> K>
|
||||
template<mp_units::Quantity Q, mp_units::QuantityOf<(mp_units::dimensionless)> K>
|
||||
[[nodiscard]] constexpr Q covariance_update(Q uncertainty, K gain)
|
||||
{
|
||||
return (1 * mp_units::one - gain) * uncertainty;
|
||||
}
|
||||
|
||||
template<mp_units::QuantityPoint... QPs, mp_units::QuantityPoint QP, mp_units::QuantityOf<mp_units::dimensionless> K>
|
||||
template<mp_units::QuantityPoint... QPs, mp_units::QuantityPoint QP, mp_units::QuantityOf<(mp_units::dimensionless)> K>
|
||||
[[nodiscard]] constexpr system_state_estimate<QPs...> state_estimate_update(
|
||||
const system_state_estimate<QPs...>& previous, QP measurement, K gain)
|
||||
{
|
||||
@@ -162,7 +162,7 @@ template<mp_units::QuantityPoint... QPs, mp_units::QuantityPoint QP, mp_units::Q
|
||||
|
||||
|
||||
// state extrapolation
|
||||
template<typename QP1, typename QP2, mp_units::QuantityOf<mp_units::isq::time> T>
|
||||
template<typename QP1, typename QP2, mp_units::QuantityOf<(mp_units::isq::time)> T>
|
||||
[[nodiscard]] constexpr system_state<QP1, QP2> state_extrapolation(const system_state<QP1, QP2>& estimated, T interval)
|
||||
{
|
||||
auto to_quantity = [](const auto& qp) { return qp.quantity_ref_from(qp.point_origin); };
|
||||
@@ -171,7 +171,7 @@ template<typename QP1, typename QP2, mp_units::QuantityOf<mp_units::isq::time> T
|
||||
return system_state<QP1, QP2>{qp1, qp2};
|
||||
}
|
||||
|
||||
template<typename QP1, typename QP2, typename QP3, mp_units::QuantityOf<mp_units::isq::time> T>
|
||||
template<typename QP1, typename QP2, typename QP3, mp_units::QuantityOf<(mp_units::isq::time)> T>
|
||||
[[nodiscard]] constexpr system_state<QP1, QP2, QP3> state_extrapolation(const system_state<QP1, QP2, QP3>& estimated,
|
||||
T interval)
|
||||
{
|
||||
|
@@ -151,7 +151,7 @@ void example()
|
||||
const auto acceleration = isq::acceleration(measurement{9.8, 0.1} * m / s2);
|
||||
const auto time = measurement{1.2, 0.1} * s;
|
||||
|
||||
const QuantityOf<isq::velocity> auto velocity = acceleration * time;
|
||||
const QuantityOf<(isq::velocity)> auto velocity = acceleration * time;
|
||||
std::cout << acceleration << " * " << time << " = " << velocity << " = " << velocity.in(km / h) << '\n';
|
||||
|
||||
const auto length = measurement{123., 1.} * m;
|
||||
|
@@ -54,8 +54,8 @@ constexpr auto h = 1 * si::si2019::planck_constant;
|
||||
constexpr auto kb = 1 * si::si2019::boltzmann_constant;
|
||||
|
||||
// prints quantities in the resulting unit
|
||||
template<QuantityOf<isq::energy> T1, QuantityOf<isq::wavenumber> T2, QuantityOf<isq::frequency> T3,
|
||||
QuantityOf<isq::thermodynamic_temperature> T4, QuantityOf<isq::wavelength> T5>
|
||||
template<QuantityOf<(isq::energy)> T1, QuantityOf<(isq::wavenumber)> T2, QuantityOf<(isq::frequency)> T3,
|
||||
QuantityOf<(isq::thermodynamic_temperature)> T4, QuantityOf<(isq::wavelength)> T5>
|
||||
void print_line(const std::tuple<T1, T2, T3, T4, T5>& t)
|
||||
{
|
||||
std::cout << MP_UNITS_STD_FMT::format(
|
||||
@@ -65,8 +65,8 @@ void print_line(const std::tuple<T1, T2, T3, T4, T5>& t)
|
||||
|
||||
// prints quantities in semi-SI units
|
||||
// (eV is not an official SI unit)
|
||||
template<QuantityOf<isq::energy> T1, QuantityOf<isq::wavenumber> T2, QuantityOf<isq::frequency> T3,
|
||||
QuantityOf<isq::thermodynamic_temperature> T4, QuantityOf<isq::wavelength> T5>
|
||||
template<QuantityOf<(isq::energy)> T1, QuantityOf<(isq::wavenumber)> T2, QuantityOf<(isq::frequency)> T3,
|
||||
QuantityOf<(isq::thermodynamic_temperature)> T4, QuantityOf<(isq::wavelength)> T5>
|
||||
void print_line_si(const std::tuple<T1, T2, T3, T4, T5>& t)
|
||||
{
|
||||
std::cout << MP_UNITS_STD_FMT::format(
|
||||
|
@@ -77,10 +77,10 @@ public:
|
||||
density_ = density;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr QuantityOf<isq::weight> auto filled_weight() const
|
||||
[[nodiscard]] constexpr QuantityOf<(isq::weight)> auto filled_weight() const
|
||||
{
|
||||
const auto volume = isq::volume(base_ * height_); // TODO check if we can remove that cast
|
||||
const QuantityOf<isq::mass> auto mass = density_ * volume;
|
||||
const QuantityOf<(isq::mass)> auto mass = density_ * volume;
|
||||
return isq::weight(mass * g);
|
||||
}
|
||||
|
||||
@@ -130,9 +130,9 @@ int main()
|
||||
const quantity spare_capacity = tank.spare_capacity(measured_mass);
|
||||
const quantity filled_weight = tank.filled_weight();
|
||||
|
||||
const QuantityOf<isq::mass_change_rate> auto input_flow_rate = measured_mass / fill_time;
|
||||
const QuantityOf<isq::speed> auto float_rise_rate = fill_level / fill_time;
|
||||
const QuantityOf<isq::time> auto fill_time_left = (height / fill_level - 1 * one) * fill_time;
|
||||
const QuantityOf<(isq::mass_change_rate)> auto input_flow_rate = measured_mass / fill_time;
|
||||
const QuantityOf<(isq::speed)> auto float_rise_rate = fill_level / fill_time;
|
||||
const QuantityOf<(isq::time)> auto fill_time_left = (height / fill_level - 1 * one) * fill_time;
|
||||
|
||||
const quantity fill_ratio = fill_level / height;
|
||||
|
||||
|
@@ -45,8 +45,8 @@ namespace {
|
||||
|
||||
using namespace mp_units;
|
||||
|
||||
QuantityOf<isq::mechanical_energy> auto total_energy(QuantityOf<isq::momentum> auto p, QuantityOf<isq::mass> auto m,
|
||||
QuantityOf<isq::speed> auto c)
|
||||
QuantityOf<(isq::mechanical_energy)> auto total_energy(QuantityOf<(isq::momentum)> auto p,
|
||||
QuantityOf<(isq::mass)> auto m, QuantityOf<(isq::speed)> auto c)
|
||||
{
|
||||
return isq::mechanical_energy(sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c))));
|
||||
}
|
||||
@@ -59,19 +59,19 @@ void si_example()
|
||||
const quantity c2 = pow<2>(c);
|
||||
|
||||
const quantity p1 = isq::momentum(4. * GeV / c);
|
||||
const QuantityOf<isq::mass> auto m1 = 3. * GeV / c2;
|
||||
const quantity E = total_energy(p1, m1, c);
|
||||
const QuantityOf<(isq::mass)> auto m1 = 3. * GeV / c2;
|
||||
const quantity E1 = total_energy(p1, m1, c);
|
||||
|
||||
std::cout << "\n*** SI units (c = " << c << " = " << c.in(si::metre / s) << ") ***\n";
|
||||
|
||||
std::cout << "\n[in `GeV` and `c`]\n"
|
||||
<< "p = " << p1 << "\n"
|
||||
<< "m = " << m1 << "\n"
|
||||
<< "E = " << E << "\n";
|
||||
<< "E = " << E1 << "\n";
|
||||
|
||||
const quantity p2 = p1.in(GeV / (m / s));
|
||||
const quantity m2 = m1.in(GeV / pow<2>(m / s));
|
||||
const quantity E2 = total_energy(p2, m2, c).in(GeV);
|
||||
const quantity metre2 = m1.in(GeV / pow<2>(m / s));
|
||||
const quantity E2 = total_energy(p2, metre2, c).in(GeV);
|
||||
|
||||
std::cout << "\n[in `GeV`]\n"
|
||||
<< "p = " << p2 << "\n"
|
||||
@@ -79,8 +79,8 @@ void si_example()
|
||||
<< "E = " << E2 << "\n";
|
||||
|
||||
const quantity p3 = p1.in(kg * m / s);
|
||||
const quantity m3 = m1.in(kg);
|
||||
const quantity E3 = total_energy(p3, m3, c).in(J);
|
||||
const quantity metre3 = m1.in(kg);
|
||||
const quantity E3 = total_energy(p3, metre3, c).in(J);
|
||||
|
||||
std::cout << "\n[in SI base units]\n"
|
||||
<< "p = " << p3 << "\n"
|
||||
|
@@ -70,6 +70,7 @@ constexpr const char* to_text(earth_gravity_model m)
|
||||
return "EGM2008-1";
|
||||
}
|
||||
assert(false && "unsupported enum value");
|
||||
return "unsupported enum value";
|
||||
}
|
||||
|
||||
template<earth_gravity_model M>
|
||||
|
Reference in New Issue
Block a user