mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-02 20:04:27 +02:00
refactor: some value_cast<U>(q)
replaced with q.force_in(U)
This commit is contained in:
@@ -56,7 +56,7 @@ constexpr QuantityOf<isq::speed> auto avg_speed(QuantityOf<isq::length> auto d,
|
||||
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 = value_cast<si::kilo<si::metre> / non_si::hour>(speed);
|
||||
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";
|
||||
}
|
||||
@@ -101,7 +101,7 @@ void example()
|
||||
|
||||
// it is not possible to make a lossless conversion of miles to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(value_cast<si::metre>(distance), duration));
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(distance.force_in(m), duration));
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
@@ -119,7 +119,7 @@ void example()
|
||||
// also it is not possible to make a lossless conversion of miles to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration,
|
||||
fixed_int_si_avg_speed(value_cast<int>(value_cast<si::metre>(distance)), value_cast<int>(duration)));
|
||||
fixed_int_si_avg_speed(value_cast<int>(distance.force_in(m)), value_cast<int>(duration)));
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
@@ -133,7 +133,7 @@ void example()
|
||||
|
||||
// it is not possible to make a lossless conversion of centimeters to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(value_cast<si::metre>(distance), duration));
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(distance.force_in(m), duration));
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
@@ -149,7 +149,7 @@ void example()
|
||||
// it is not possible to make a lossless conversion of centimeters to meters on an integral type
|
||||
// (explicit cast needed)
|
||||
print_result(distance, duration,
|
||||
fixed_int_si_avg_speed(value_cast<int>(value_cast<m>(distance)), value_cast<int>(duration)));
|
||||
fixed_int_si_avg_speed(value_cast<int>(distance.force_in(m)), value_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
|
@@ -83,12 +83,12 @@ void print(const R& gliders)
|
||||
std::cout << "- Name: " << g.name << "\n";
|
||||
std::cout << "- Polar:\n";
|
||||
for (const auto& p : g.polar) {
|
||||
const auto ratio = value_cast<one>(glide_ratio(g.polar[0]));
|
||||
const auto ratio = glide_ratio(g.polar[0]).force_in(one);
|
||||
std::cout << MP_UNITS_STD_FMT::format(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q} ({:%.1Q %q})\n", p.climb, p.v,
|
||||
ratio,
|
||||
// TODO is it possible to make ADL work below (we need another set of trig
|
||||
// functions for strong angle in a different namespace)
|
||||
value_cast<si::degree>(isq::asin(1 / ratio)));
|
||||
isq::asin(1 / ratio).force_in(si::degree));
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
@@ -80,7 +80,7 @@ void si_example()
|
||||
<< "E = " << E3 << "\n";
|
||||
|
||||
std::cout << "\n[converted from SI units back to GeV]\n"
|
||||
<< "E = " << value_cast<GeV>(E3) << "\n";
|
||||
<< "E = " << E3.force_in(GeV) << "\n";
|
||||
}
|
||||
|
||||
void natural_example()
|
||||
|
@@ -162,7 +162,7 @@ template<Unit auto To, auto R, typename Rep>
|
||||
|
||||
requires { std::floor(q.numerical_value_ref_in(q.unit)); }) &&
|
||||
(To == get_unit(R) || requires {
|
||||
::mp_units::value_cast<To>(q);
|
||||
q.force_in(To);
|
||||
quantity_values<Rep>::one();
|
||||
})
|
||||
{
|
||||
@@ -183,9 +183,9 @@ template<Unit auto To, auto R, typename Rep>
|
||||
}
|
||||
} else {
|
||||
if constexpr (To == get_unit(R)) {
|
||||
return value_cast<To>(q);
|
||||
return q.force_in(To);
|
||||
} else {
|
||||
return handle_signed_results(value_cast<To>(q));
|
||||
return handle_signed_results(q.force_in(To));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,7 +202,7 @@ template<Unit auto To, auto R, typename Rep>
|
||||
|
||||
requires { std::ceil(q.numerical_value_ref_in(q.unit)); }) &&
|
||||
(To == get_unit(R) || requires {
|
||||
::mp_units::value_cast<To>(q);
|
||||
q.force_in(To);
|
||||
quantity_values<Rep>::one();
|
||||
})
|
||||
{
|
||||
@@ -223,9 +223,9 @@ template<Unit auto To, auto R, typename Rep>
|
||||
}
|
||||
} else {
|
||||
if constexpr (To == get_unit(R)) {
|
||||
return value_cast<To>(q);
|
||||
return q.force_in(To);
|
||||
} else {
|
||||
return handle_signed_results(value_cast<To>(q));
|
||||
return handle_signed_results(q.force_in(To));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ template<Unit auto To, auto R, typename Rep>
|
||||
return make_quantity<detail::clone_reference_with<To>(R)>(
|
||||
static_cast<Rep>(round(q.numerical_value_ref_in(q.unit))));
|
||||
} else {
|
||||
return value_cast<To>(q);
|
||||
return q.force_in(To);
|
||||
}
|
||||
} else {
|
||||
const auto res_low = mp_units::floor<To>(q);
|
||||
|
Reference in New Issue
Block a user