forked from mpusz/mp-units
style: clang-format applied to the remaining files
This commit is contained in:
@@ -21,12 +21,12 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/cgs/length.h>
|
||||
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/international/length.h>
|
||||
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/length.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -35,38 +35,31 @@ namespace {
|
||||
|
||||
using namespace units::isq;
|
||||
|
||||
constexpr si::speed<si::metre_per_second, int>
|
||||
fixed_int_si_avg_speed(si::length<si::metre, int> d,
|
||||
si::time<si::second, int> t)
|
||||
constexpr si::speed<si::metre_per_second, int> fixed_int_si_avg_speed(si::length<si::metre, int> d,
|
||||
si::time<si::second, int> t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
constexpr si::speed<si::metre_per_second>
|
||||
fixed_double_si_avg_speed(si::length<si::metre> d,
|
||||
si::time<si::second> t)
|
||||
constexpr si::speed<si::metre_per_second> fixed_double_si_avg_speed(si::length<si::metre> d, si::time<si::second> t)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
|
||||
template<typename U1, typename R1, typename U2, typename R2>
|
||||
constexpr Speed auto si_avg_speed(si::length<U1, R1> d,
|
||||
si::time<U2, R2> t)
|
||||
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)
|
||||
{
|
||||
return d / t;
|
||||
}
|
||||
constexpr Speed auto avg_speed(Length auto d, Time auto t) { return d / t; }
|
||||
|
||||
template<Length D, Time T, Speed V>
|
||||
void print_result(D distance, T duration, V speed)
|
||||
{
|
||||
const auto result_in_kmph = units::quantity_cast<si::speed<si::kilometre_per_hour>>(speed);
|
||||
std::cout << "Average speed of a car that makes " << distance << " in "
|
||||
<< duration << " is " << result_in_kmph << ".\n";
|
||||
std::cout << "Average speed of a car that makes " << distance << " in " << duration << " is " << result_in_kmph
|
||||
<< ".\n";
|
||||
}
|
||||
|
||||
void example()
|
||||
@@ -94,7 +87,8 @@ void example()
|
||||
std::cout << "\nSI units with 'double' as representation\n";
|
||||
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<int>(distance), quantity_cast<int>(duration)));
|
||||
print_result(distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<int>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, si_avg_speed(distance, duration));
|
||||
@@ -130,7 +124,9 @@ void example()
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
// 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(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
print_result(
|
||||
distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
print_result(distance, duration, si_avg_speed(distance, duration));
|
||||
@@ -169,7 +165,9 @@ void example()
|
||||
// conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed
|
||||
// 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(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
print_result(
|
||||
distance, duration,
|
||||
fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||
|
||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||
|
||||
@@ -178,20 +176,17 @@ void example()
|
||||
|
||||
print_result(distance, duration, avg_speed(distance, duration));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <units/isq/si/force.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/volume.h>
|
||||
#include <cassert>
|
||||
@@ -50,7 +50,10 @@ class Box {
|
||||
si::length<si::metre> height_;
|
||||
si::density<si::kilogram_per_metre_cub> density_ = air_density;
|
||||
public:
|
||||
constexpr Box(const si::length<si::metre>& length, const si::length<si::metre>& width, si::length<si::metre> height) : base_(length * width), height_(std::move(height)) {}
|
||||
constexpr Box(const si::length<si::metre>& length, const si::length<si::metre>& width, si::length<si::metre> height) :
|
||||
base_(length * width), height_(std::move(height))
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr si::force<si::newton> filled_weight() const
|
||||
{
|
||||
@@ -90,13 +93,13 @@ int main()
|
||||
auto box = Box(1000.0 * mm, 500.0 * mm, height);
|
||||
box.set_contents_density(1000.0 * (kg / m3));
|
||||
|
||||
const auto fill_time = 200.0 * s; // time since starting fill
|
||||
const auto measured_mass = 20.0 * kg; // measured mass at fill_time
|
||||
const auto fill_time = 200.0 * s; // time since starting fill
|
||||
const auto measured_mass = 20.0 * kg; // measured mass at fill_time
|
||||
|
||||
const Length auto fill_level = box.fill_level(measured_mass);
|
||||
const Dimensionless auto fill_percent = quantity_cast<percent>(fill_level / height);
|
||||
const Volume auto spare_capacity = box.spare_capacity(measured_mass);
|
||||
const auto input_flow_rate = measured_mass / fill_time; // unknown dimension
|
||||
const auto input_flow_rate = measured_mass / fill_time; // unknown dimension
|
||||
const Speed auto float_rise_rate = fill_level / fill_time;
|
||||
const Time auto fill_time_left = (height / fill_level - 1) * fill_time;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <units/isq/si/resistance.h>
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/isq/si/voltage.h>
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/math.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -39,15 +39,15 @@ void simple_quantities()
|
||||
using distance = si::length<si::metre>;
|
||||
using duration = si::time<si::second>;
|
||||
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
constexpr distance km = 1.0 * references::km;
|
||||
constexpr distance miles = 1.0 * mi;
|
||||
|
||||
constexpr duration sec = 1 * s;
|
||||
constexpr duration min = 1 * references::min;
|
||||
constexpr duration hr = 1 * h;
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
|
||||
std::cout << "A physical quantities library can choose the simple\n";
|
||||
std::cout << "option to provide output using a single type for each base unit:\n\n";
|
||||
@@ -66,8 +66,8 @@ void quantities_with_typed_units()
|
||||
using namespace units::isq::si::international;
|
||||
using namespace units::isq::si::international::references;
|
||||
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
constexpr length<kilometre> km = 1.0 * si::references::km;
|
||||
constexpr length<mile> miles = 1.0 * mi;
|
||||
|
||||
@@ -76,7 +76,7 @@ UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
constexpr si::time<second> sec = 1 * s;
|
||||
constexpr si::time<minute> min = 1 * si::references::min;
|
||||
constexpr si::time<hour> hr = 1 * h;
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
|
||||
std::cout << "A more flexible option is to provide separate types for each unit,\n\n";
|
||||
std::cout << km << '\n';
|
||||
|
||||
@@ -20,17 +20,17 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/bits/external/hacks.h> // IWYU pragma: keep
|
||||
#include <units/bits/external/hacks.h> // IWYU pragma: keep
|
||||
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_SHADOW
|
||||
#include <units/isq/si/force.h> // 'N' (Newton) shadows a template parameter traditionally used as a size of the array
|
||||
#include <units/isq/si/force.h> // 'N' (Newton) shadows a template parameter traditionally used as a size of the array
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
|
||||
#include <units/generic/angle.h>
|
||||
#include <units/isq/si/energy.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/torque.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/torque.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/fps/density.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/fps/density.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/fps/length.h>
|
||||
#include <units/isq/si/fps/mass.h>
|
||||
#include <units/isq/si/fps/power.h>
|
||||
@@ -56,7 +56,7 @@ struct Ship {
|
||||
};
|
||||
|
||||
// Print 'a' in its current units and print its value cast to the units in each of Args
|
||||
template<class ...Args, units::Quantity Q>
|
||||
template<class... Args, units::Quantity Q>
|
||||
auto fmt_line(const Q a)
|
||||
{
|
||||
return STD_FMT::format("{:22}", a) + (STD_FMT::format(",{:20}", units::quantity_cast<Args>(a)) + ...);
|
||||
@@ -68,16 +68,27 @@ void print_details(std::string_view description, const Ship& ship)
|
||||
using namespace units::isq::si::fps::references;
|
||||
const auto waterDensity = 62.4 * (lb / ft3);
|
||||
std::cout << STD_FMT::format("{}\n", description);
|
||||
std::cout << STD_FMT::format("{:20} : {}\n", "length", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.length))
|
||||
<< STD_FMT::format("{:20} : {}\n", "draft", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.draft))
|
||||
<< STD_FMT::format("{:20} : {}\n", "beam", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.beam))
|
||||
<< STD_FMT::format("{:20} : {}\n", "mass", fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::tonne>>(ship.mass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "speed", fmt_line<si::fps::speed<si::fps::knot>, si::speed<si::kilometre_per_hour>>(ship.speed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "power", fmt_line<si::fps::power<si::fps::horse_power>, si::power<si::kilowatt>>(ship.power))
|
||||
<< STD_FMT::format("{:20} : {}\n", "main guns", fmt_line<si::fps::length<si::fps::inch>, si::length<si::millimetre>>(ship.mainGuns))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells weighing", fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::kilogram>>(ship.shellMass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells at", fmt_line<si::fps::speed<si::fps::mile_per_hour>, si::speed<si::kilometre_per_hour>>(ship.shellSpeed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "volume underwater", fmt_line<si::volume<si::cubic_metre>, si::volume<si::litre>>(ship.mass / waterDensity));
|
||||
std::cout << STD_FMT::format("{:20} : {}\n", "length",
|
||||
fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.length))
|
||||
<< STD_FMT::format("{:20} : {}\n", "draft",
|
||||
fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.draft))
|
||||
<< STD_FMT::format("{:20} : {}\n", "beam",
|
||||
fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.beam))
|
||||
<< STD_FMT::format("{:20} : {}\n", "mass",
|
||||
fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::tonne>>(ship.mass))
|
||||
<< STD_FMT::format("{:20} : {}\n", "speed",
|
||||
fmt_line<si::fps::speed<si::fps::knot>, si::speed<si::kilometre_per_hour>>(ship.speed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "power",
|
||||
fmt_line<si::fps::power<si::fps::horse_power>, si::power<si::kilowatt>>(ship.power))
|
||||
<< STD_FMT::format("{:20} : {}\n", "main guns",
|
||||
fmt_line<si::fps::length<si::fps::inch>, si::length<si::millimetre>>(ship.mainGuns))
|
||||
<< STD_FMT::format("{:20} : {}\n", "fire shells weighing",
|
||||
fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::kilogram>>(ship.shellMass))
|
||||
<< STD_FMT::format(
|
||||
"{:20} : {}\n", "fire shells at",
|
||||
fmt_line<si::fps::speed<si::fps::mile_per_hour>, si::speed<si::kilometre_per_hour>>(ship.shellSpeed))
|
||||
<< STD_FMT::format("{:20} : {}\n", "volume underwater",
|
||||
fmt_line<si::volume<si::cubic_metre>, si::volume<si::litre>>(ship.mass / waterDensity));
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -87,13 +98,37 @@ int main()
|
||||
using units::isq::si::fps::references::ft; // collides with si::femtotonne (alias unit of mass)
|
||||
|
||||
// KMS Bismark, using the units the Germans would use, taken from Wiki
|
||||
auto bismark = Ship{.length{251. * m}, .draft{9.3 * m}, .beam{36 * m}, .speed{56 * (km / h)}, .mass{50'300 * t}, .mainGuns{380 * mm}, .shellMass{800 * kg}, .shellSpeed{820. * (m / s)}, .power{110.45 * kW}};
|
||||
auto bismark = Ship{.length{251. * m},
|
||||
.draft{9.3 * m},
|
||||
.beam{36 * m},
|
||||
.speed{56 * (km / h)},
|
||||
.mass{50'300 * t},
|
||||
.mainGuns{380 * mm},
|
||||
.shellMass{800 * kg},
|
||||
.shellSpeed{820. * (m / s)},
|
||||
.power{110.45 * kW}};
|
||||
|
||||
// USS Iowa, using units from the foot-pound-second system
|
||||
auto iowa = Ship{.length{860. * ft}, .draft{37. * ft + 2. * in}, .beam{108. * ft + 2. * in}, .speed{33 * knot}, .mass{57'540 * lton}, .mainGuns{16 * in}, .shellMass{2700 * lb}, .shellSpeed{2690. * (ft / s)}, .power{212'000 * hp}};
|
||||
auto iowa = Ship{.length{860. * ft},
|
||||
.draft{37. * ft + 2. * in},
|
||||
.beam{108. * ft + 2. * in},
|
||||
.speed{33 * knot},
|
||||
.mass{57'540 * lton},
|
||||
.mainGuns{16 * in},
|
||||
.shellMass{2700 * lb},
|
||||
.shellSpeed{2690. * (ft / s)},
|
||||
.power{212'000 * hp}};
|
||||
|
||||
// HMS King George V, using units from the foot-pound-second system
|
||||
auto kgv = Ship{.length{745.1 * ft}, .draft{33. * ft + 7.5 * in}, .beam{103.2 * ft + 2.5 * in}, .speed{28.3 * knot}, .mass{42'245 * lton}, .mainGuns{14 * in}, .shellMass{1'590 * lb}, .shellSpeed{2483. * (ft / s)}, .power{110'000 * hp}};
|
||||
auto kgv = Ship{.length{745.1 * ft},
|
||||
.draft{33. * ft + 7.5 * in},
|
||||
.beam{103.2 * ft + 2.5 * in},
|
||||
.speed{28.3 * knot},
|
||||
.mass{42'245 * lton},
|
||||
.mainGuns{14 * in},
|
||||
.shellMass{1'590 * lb},
|
||||
.shellSpeed{2483. * (ft / s)},
|
||||
.power{110'000 * hp}};
|
||||
|
||||
print_details("KMS Bismark, defined in appropriate units from the SI system", bismark);
|
||||
std::cout << "\n\n";
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <units/chrono.h>
|
||||
#include <units/generic/dimensionless.h>
|
||||
#include <units/isq/si/international/length.h>
|
||||
|
||||
#include <array>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -43,14 +42,14 @@ using namespace units::isq;
|
||||
auto get_gliders()
|
||||
{
|
||||
using namespace si::references;
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
UNITS_DIAGNOSTIC_PUSH
|
||||
UNITS_DIAGNOSTIC_IGNORE_MISSING_BRACES
|
||||
static const std::array gliders = {
|
||||
glider{"SZD-30 Pirat", {velocity(83 * (km / h)), rate_of_climb(-0.7389 * (m / s))}},
|
||||
glider{"SZD-51 Junior", {velocity(80 * (km / h)), rate_of_climb(-0.6349 * (m / s))}},
|
||||
glider{"SZD-48 Jantar Std 3", {velocity(110 * (km / h)), rate_of_climb(-0.77355 * (m / s))}},
|
||||
glider{"SZD-56 Diana", {velocity(110 * (km / h)), rate_of_climb(-0.63657 * (m / s))}}};
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
glider{"SZD-30 Pirat", {velocity(83 * (km / h)), rate_of_climb(-0.7389 * (m / s))}},
|
||||
glider{"SZD-51 Junior", {velocity(80 * (km / h)), rate_of_climb(-0.6349 * (m / s))}},
|
||||
glider{"SZD-48 Jantar Std 3", {velocity(110 * (km / h)), rate_of_climb(-0.77355 * (m / s))}},
|
||||
glider{"SZD-56 Diana", {velocity(110 * (km / h)), rate_of_climb(-0.63657 * (m / s))}}};
|
||||
UNITS_DIAGNOSTIC_POP
|
||||
return gliders;
|
||||
}
|
||||
|
||||
@@ -58,9 +57,9 @@ auto get_weather_conditions()
|
||||
{
|
||||
using namespace si::references;
|
||||
static const std::array weather_conditions = {
|
||||
std::pair("Good", weather{height(1900 * m), rate_of_climb(4.3 * (m / s))}),
|
||||
std::pair("Medium", weather{height(1550 * m), rate_of_climb(2.8 * (m / s))}),
|
||||
std::pair("Bad", weather{height(850 * m), rate_of_climb(1.8 * (m / s))})};
|
||||
std::pair("Good", weather{height(1900 * m), rate_of_climb(4.3 * (m / s))}),
|
||||
std::pair("Medium", weather{height(1550 * m), rate_of_climb(2.8 * (m / s))}),
|
||||
std::pair("Bad", weather{height(850 * m), rate_of_climb(1.8 * (m / s))})};
|
||||
return weather_conditions;
|
||||
}
|
||||
|
||||
@@ -69,14 +68,14 @@ auto get_waypoints()
|
||||
using namespace geographic::literals;
|
||||
using namespace units::isq::si::international::references;
|
||||
static const std::array waypoints = {
|
||||
waypoint{"EPPR", {54.24772_N, 18.6745_E}, altitude(16 * ft)}, // N54°14'51.8" E18°40'28.2"
|
||||
waypoint{"EPGI", {53.52442_N, 18.84947_E}, altitude(115 * ft)} // N53°31'27.9" E18°50'58.1"
|
||||
waypoint{"EPPR", {54.24772_N, 18.6745_E}, altitude(16 * ft)}, // N54°14'51.8" E18°40'28.2"
|
||||
waypoint{"EPGI", {53.52442_N, 18.84947_E}, altitude(115 * ft)} // N53°31'27.9" E18°50'58.1"
|
||||
};
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, glider>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, glider>)
|
||||
void print(const R& gliders)
|
||||
{
|
||||
std::cout << "Gliders:\n";
|
||||
@@ -85,13 +84,14 @@ void print(const R& gliders)
|
||||
std::cout << "- Name: " << g.name << "\n";
|
||||
std::cout << "- Polar:\n";
|
||||
for (const auto& p : g.polar)
|
||||
std::cout << STD_FMT::format(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q}\n", p.climb, p.v, units::quantity_cast<units::one>(glide_ratio(g.polar[0])));
|
||||
std::cout << STD_FMT::format(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q}\n", p.climb, p.v,
|
||||
units::quantity_cast<units::one>(glide_ratio(g.polar[0])));
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, std::pair<const char*, weather>>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, std::pair<const char*, weather>>)
|
||||
void print(const R& conditions)
|
||||
{
|
||||
std::cout << "Weather:\n";
|
||||
@@ -106,7 +106,7 @@ void print(const R& conditions)
|
||||
}
|
||||
|
||||
template<std::ranges::input_range R>
|
||||
requires std::same_as<std::ranges::range_value_t<R>, waypoint>
|
||||
requires(std::same_as<std::ranges::range_value_t<R>, waypoint>)
|
||||
void print(const R& waypoints)
|
||||
{
|
||||
std::cout << "Waypoints:\n";
|
||||
@@ -125,7 +125,8 @@ void print(const task& t)
|
||||
std::cout << "- Finish: " << t.get_finish().name << "\n";
|
||||
std::cout << "- Length: " << STD_FMT::format("{:%.1Q %q}", t.get_length()) << "\n";
|
||||
|
||||
std::cout << "- Legs: " << "\n";
|
||||
std::cout << "- Legs: "
|
||||
<< "\n";
|
||||
for (const auto& l : t.get_legs())
|
||||
std::cout << STD_FMT::format(" * {} -> {} ({:%.1Q %q})\n", l.begin().name, l.end().name, l.get_length());
|
||||
std::cout << "\n";
|
||||
|
||||
@@ -20,14 +20,14 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/energy.h> // IWYU pragma: keep
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/energy.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/force.h>
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/format.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/quantity_io.h>
|
||||
#include <linear_algebra.hpp>
|
||||
#include <iostream>
|
||||
#include <linear_algebra.hpp>
|
||||
|
||||
namespace STD_LA {
|
||||
|
||||
@@ -73,9 +73,9 @@ void vector_of_quantity_add()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_add:\n";
|
||||
|
||||
vector<si::length<si::metre>> v = { 1 * m, 2 * m, 3 * m };
|
||||
vector<si::length<si::metre>> u = { 3 * m, 2 * m, 1 * m };
|
||||
vector<si::length<si::kilometre>> t = { 3 * km, 2 * km, 1 * km };
|
||||
vector<si::length<si::metre>> v = {1 * m, 2 * m, 3 * m};
|
||||
vector<si::length<si::metre>> u = {3 * m, 2 * m, 1 * m};
|
||||
vector<si::length<si::kilometre>> t = {3 * km, 2 * km, 1 * km};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -90,8 +90,8 @@ void vector_of_quantity_multiply_same()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_multiply_same:\n";
|
||||
|
||||
vector<si::length<si::metre>> v = { 1 * m, 2 * m, 3 * m };
|
||||
vector<si::length<si::metre>> u = { 3 * m, 2 * m, 1 * m };
|
||||
vector<si::length<si::metre>> v = {1 * m, 2 * m, 3 * m};
|
||||
vector<si::length<si::metre>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -104,8 +104,8 @@ void vector_of_quantity_multiply_different()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_multiply_different:\n";
|
||||
|
||||
vector<si::force<si::newton>> v = { 1 * N, 2 * N, 3 * N };
|
||||
vector<si::length<si::metre>> u = { 3 * m, 2 * m, 1 * m };
|
||||
vector<si::force<si::newton>> v = {1 * N, 2 * N, 3 * N};
|
||||
vector<si::length<si::metre>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -119,7 +119,7 @@ void vector_of_quantity_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nvector_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
vector<si::length<si::metre>> v = { 4 * m, 8 * m, 12 * m };
|
||||
vector<si::length<si::metre>> v = {4 * m, 8 * m, 12 * m};
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
|
||||
@@ -140,9 +140,9 @@ void matrix_of_quantity_add()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_add:\n";
|
||||
|
||||
matrix<si::length<si::metre>> v = {{ 1 * m, 2 * m, 3 * m }, { 4 * m, 5 * m, 6 * m }, { 7 * m, 8 * m, 9 * m }};
|
||||
matrix<si::length<si::metre>> u = {{ 3 * m, 2 * m, 1 * m }, { 3 * m, 2 * m, 1 * m }, { 3 * m, 2 * m, 1 * m }};
|
||||
matrix<si::length<si::millimetre>> t = {{ 3 * mm, 2 * mm, 1 * mm }, { 3 * mm, 2 * mm, 1 * mm }, { 3 * mm, 2 * mm, 1 * mm }};
|
||||
matrix<si::length<si::metre>> v = {{1 * m, 2 * m, 3 * m}, {4 * m, 5 * m, 6 * m}, {7 * m, 8 * m, 9 * m}};
|
||||
matrix<si::length<si::metre>> u = {{3 * m, 2 * m, 1 * m}, {3 * m, 2 * m, 1 * m}, {3 * m, 2 * m, 1 * m}};
|
||||
matrix<si::length<si::millimetre>> t = {{3 * mm, 2 * mm, 1 * mm}, {3 * mm, 2 * mm, 1 * mm}, {3 * mm, 2 * mm, 1 * mm}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -159,8 +159,8 @@ void matrix_of_quantity_multiply_same()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_multiply_same:\n";
|
||||
|
||||
matrix<si::length<si::metre>> v = {{ 1 * m, 2 * m, 3 * m }, { 4 * m, 5 * m, 6 * m }, { 7 * m, 8 * m, 9 * m }};
|
||||
vector<si::length<si::metre>> u = { 3 * m, 2 * m, 1 * m };
|
||||
matrix<si::length<si::metre>> v = {{1 * m, 2 * m, 3 * m}, {4 * m, 5 * m, 6 * m}, {7 * m, 8 * m, 9 * m}};
|
||||
vector<si::length<si::metre>> u = {3 * m, 2 * m, 1 * m};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -173,8 +173,8 @@ void matrix_of_quantity_multiply_different()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_multiply_different:\n";
|
||||
|
||||
vector<si::force<si::newton>> v = { 1 * N, 2 * N, 3 * N };
|
||||
matrix<si::length<si::metre>> u = {{ 1 * m, 2 * m, 3 * m }, { 4 * m, 5 * m, 6 * m }, { 7 * m, 8 * m, 9 * m }};
|
||||
vector<si::force<si::newton>> v = {1 * N, 2 * N, 3 * N};
|
||||
matrix<si::length<si::metre>> u = {{1 * m, 2 * m, 3 * m}, {4 * m, 5 * m, 6 * m}, {7 * m, 8 * m, 9 * m}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -188,7 +188,7 @@ void matrix_of_quantity_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nmatrix_of_quantity_divide_by_scalar:\n";
|
||||
|
||||
matrix<si::length<si::metre>> v = {{ 2 * m, 4 * m, 6 * m }, { 4 * m, 6 * m, 8 * m }, { 8 * m, 4 * m, 2 * m }};
|
||||
matrix<si::length<si::metre>> v = {{2 * m, 4 * m, 6 * m}, {4 * m, 6 * m, 8 * m}, {8 * m, 4 * m, 2 * m}};
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
|
||||
@@ -215,9 +215,9 @@ void quantity_of_vector_add()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_add:\n";
|
||||
|
||||
length_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_v<si::kilometre> t(vector<>{ 3, 2, 1 });
|
||||
length_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
length_v<si::kilometre> t(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -232,8 +232,8 @@ void quantity_of_vector_multiply_same()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_multiply_same:\n";
|
||||
|
||||
length_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -246,8 +246,8 @@ void quantity_of_vector_multiply_different()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_multiply_different:\n";
|
||||
|
||||
force_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
force_v<> v(vector<>{1, 2, 3});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
std::cout << "u = " << u << "\n";
|
||||
@@ -261,7 +261,7 @@ void quantity_of_vector_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nquantity_of_vector_divide_by_scalar:\n";
|
||||
|
||||
length_v<> v(vector<>{ 4, 8, 12 });
|
||||
length_v<> v(vector<>{4, 8, 12});
|
||||
|
||||
std::cout << "v = " << v << "\n";
|
||||
|
||||
@@ -285,9 +285,9 @@ void quantity_of_matrix_add()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_add:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
length_m<> u(matrix<>{{ 3, 2, 1 }, { 3, 2, 1 }, { 3, 2, 1 }});
|
||||
length_m<si::kilometre> t(matrix<>{{ 3, 2, 1 }, { 3, 2, 1 }, { 3, 2, 1 }});
|
||||
length_m<> v(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
length_m<> u(matrix<>{{3, 2, 1}, {3, 2, 1}, {3, 2, 1}});
|
||||
length_m<si::kilometre> t(matrix<>{{3, 2, 1}, {3, 2, 1}, {3, 2, 1}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -304,8 +304,8 @@ void quantity_of_matrix_multiply_same()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_multiply_same:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
length_v<> u(vector<>{ 3, 2, 1 });
|
||||
length_m<> v(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
length_v<> u(vector<>{3, 2, 1});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -318,8 +318,8 @@ void quantity_of_matrix_multiply_different()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_multiply_different:\n";
|
||||
|
||||
force_v<> v(vector<>{ 1, 2, 3 });
|
||||
length_m<> u(matrix<>{{ 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }});
|
||||
force_v<> v(vector<>{1, 2, 3});
|
||||
length_m<> u(matrix<>{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
std::cout << "u =\n" << u << "\n";
|
||||
@@ -333,7 +333,7 @@ void quantity_of_matrix_divide_by_scalar()
|
||||
{
|
||||
std::cout << "\nquantity_of_matrix_divide_by_scalar:\n";
|
||||
|
||||
length_m<> v(matrix<>{{ 2, 4, 6 }, { 4, 6, 8 }, { 8, 4, 2 }});
|
||||
length_m<> v(matrix<>{{2, 4, 6}, {4, 6, 8}, {8, 4, 2}});
|
||||
|
||||
std::cout << "v =\n" << v << "\n";
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <units/isq/si/energy.h>
|
||||
#include <units/isq/si/mass.h>
|
||||
#include <units/isq/si/momentum.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/math.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
@@ -87,18 +87,16 @@ void natural_example()
|
||||
<< "E = " << E << "\n";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
si_example();
|
||||
natural_example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/isq/si/length.h>
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/speed.h> // IWYU pragma: keep
|
||||
#include <units/isq/si/time.h>
|
||||
#include <units/quantity_io.h>
|
||||
#include <exception>
|
||||
@@ -44,8 +44,9 @@ void example()
|
||||
Time auto t1 = 10 * s;
|
||||
Speed auto v1 = avg_speed(d1, t1);
|
||||
|
||||
auto temp1 = v1 * (50 * m); // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
|
||||
Speed auto v2 = temp1 / (100 * m); // back to known dimensions again
|
||||
auto temp1 =
|
||||
v1 * (50 * m); // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
|
||||
Speed auto v2 = temp1 / (100 * m); // back to known dimensions again
|
||||
Length auto d2 = v2 * (60 * s);
|
||||
|
||||
std::cout << "d1 = " << d1 << '\n';
|
||||
@@ -56,17 +57,15 @@ void example()
|
||||
std::cout << "d2 = " << d2 << '\n';
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
try {
|
||||
example();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
} catch (const std::exception& ex) {
|
||||
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';
|
||||
}
|
||||
catch (...) {
|
||||
} catch (...) {
|
||||
std::cerr << "Unhandled unknown exception caught\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user