refactor: 💥 q_* UDL renamed to _q_*

We had some fun exploring the STD UDLs for potential collisions,
we have learnt our lesson and know how to proceed.
Now is high time to start behaving and obeying C++ rules.
This commit is contained in:
Mateusz Pusz
2020-09-09 19:20:35 +02:00
parent 2b408f19c0
commit 9527b39005
130 changed files with 2221 additions and 2235 deletions
@@ -56,11 +56,11 @@ using namespace units::physical::si::literals;
int main()
{
auto box = Box{1000.0q_mm, 500.0q_mm, 200.0q_mm};
box.set_contents_density(1000.0q_kg_per_m3);
auto box = Box{1000.0_q_mm, 500.0_q_mm, 200.0_q_mm};
box.set_contents_density(1000.0_q_kg_per_m3);
auto fill_time = 200.0q_s; // time since starting fill
auto measured_mass = 20.0q_kg; // measured mass at fill_time
auto fill_time = 200.0_q_s; // time since starting fill
auto measured_mass = 20.0_q_kg; // measured mass at fill_time
std::cout << "mpusz/units box example ( using experimental alternative syntax for defining quantities) ...\n";
std::cout << "fill height at " << fill_time << " = " << box.fill_level(measured_mass) << " ("
@@ -36,22 +36,22 @@ int main()
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
std::cout.precision(3);
constexpr auto C = 0.47q_uF;
constexpr auto V0 = 5.0q_V;
constexpr auto R = 4.7q_kR;
constexpr auto C = 0.47_q_uF;
constexpr auto V0 = 5.0_q_V;
constexpr auto R = 4.7_q_kR;
for (auto t = 0q_ms; t <= 50q_ms; ++t) {
for (auto t = 0_q_ms; t <= 50_q_ms; ++t) {
const auto Vt = V0 * units::exp(-t / (R * C));
std::cout << "at " << t << " voltage is ";
if (Vt >= 1q_V)
if (Vt >= 1_q_V)
std::cout << Vt;
else if (Vt >= 1q_mV)
else if (Vt >= 1_q_mV)
std::cout << voltage::mV<>{Vt};
else if (Vt >= 1q_uV)
else if (Vt >= 1_q_uV)
std::cout << voltage::uV<>{Vt};
else if (Vt >= 1q_nV)
else if (Vt >= 1_q_nV)
std::cout << voltage::nV<>{Vt};
else
std::cout << voltage::pV<>{Vt};
@@ -33,12 +33,12 @@ void simple_quantities()
using distance = length::m<>;
using q_time = q_time::s<>;
constexpr distance km = 1.0q_km;
constexpr distance miles = 1.0q_mi;
constexpr distance km = 1.0_q_km;
constexpr distance miles = 1.0_q_mi;
constexpr q_time sec = 1q_s;
constexpr q_time min = 1q_min;
constexpr q_time hr = 1q_h;
constexpr q_time sec = 1_q_s;
constexpr q_time min = 1_q_min;
constexpr q_time hr = 1_q_h;
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";
@@ -51,12 +51,12 @@ void simple_quantities()
void quantities_with_typed_units()
{
constexpr length::km<> km = 1.0q_km;
constexpr length::mi<> miles = 1.0q_mi;
constexpr length::km<> km = 1.0_q_km;
constexpr length::mi<> miles = 1.0_q_mi;
constexpr q_time::s<> sec = 1q_s;
constexpr q_time::min<> min = 1q_min;
constexpr q_time::h<> hr = 1q_h;
constexpr q_time::s<> sec = 1_q_s;
constexpr q_time::min<> min = 1_q_min;
constexpr q_time::h<> hr = 1_q_h;
std::cout << "A more flexible option is to provide separate types for each unit,\n\n";
std::cout << km << '\n';
@@ -65,7 +65,7 @@ void quantities_with_typed_units()
std::cout << min << '\n';
std::cout << hr << "\n\n";
constexpr length::m<> meter = 1q_m;
constexpr length::m<> meter = 1_q_m;
std::cout << "then a wide range of pre-defined units can be defined and converted,\n"
" for consistency and repeatability across applications:\n\n";
@@ -97,8 +97,8 @@ void calcs_comparison()
"when adding two values of the same very big\n"
"or very small type:\n\n";
length::fm<float> L1A = 2.q_fm;
length::fm<float> L2A = 3.q_fm;
length::fm<float> L1A = 2._q_fm;
length::fm<float> L2A = 3._q_fm;
length::fm<float> LrA = L1A + L2A;
fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n",L1A,L2A,LrA);
@@ -47,7 +47,7 @@ int main()
{
std::cout << "conversion factor in mpusz/units...\n\n";
constexpr length::m<> lengthA = 2.0q_m;
constexpr length::m<> lengthA = 2.0_q_m;
constexpr length::mm<> lengthB = lengthA;
std::cout << "lengthA( " << lengthA << " ) and lengthB( " << lengthB << " )\n"
+1 -1
View File
@@ -13,7 +13,7 @@ int main()
{
std::cout << "Simple timer using mpusz/units ...\n";
auto const period = 0.5q_s;
auto const period = 0.5_q_s;
auto const duration = 10 * period;
timer t;
+8 -8
View File
@@ -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 = 220_q_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 = 140_q_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,8 +114,8 @@ void example()
// Customary Units (double)
{
using namespace units::physical::international::literals;
constexpr Length auto distance = 140.q_mi; // constructed from a UDL
constexpr si::time<si::hour> duration(2); // constructed from a value
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'000_q_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,8 +151,8 @@ void example()
// CGS (double)
{
using namespace units::physical::cgs::literals;
constexpr Length auto distance = 22'000'000.q_cm; // constructed from a UDL
constexpr cgs::time<si::hour> duration(2); // constructed from a value
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";
+5 -5
View File
@@ -25,7 +25,7 @@ inline constexpr auto g = si::si2019::standard_gravity<>;
} // namespace
struct Box {
static constexpr auto air_density = 1.225q_kg_per_m3;
static constexpr auto air_density = 1.225_q_kg_per_m3;
si::length<m> length;
si::length<m> width;
@@ -65,11 +65,11 @@ struct Box {
int main()
{
auto box = Box(1000.0q_mm, 500.0q_mm, 200.0q_mm);
box.set_contents_density(1000.0q_kg_per_m3);
auto box = Box(1000.0_q_mm, 500.0_q_mm, 200.0_q_mm);
box.set_contents_density(1000.0_q_kg_per_m3);
const auto fill_time = 200.0q_s; // time since starting fill
const auto measured_mass = 20.0q_kg; // measured mass at fill_time
const auto fill_time = 200.0_q_s; // time since starting fill
const auto measured_mass = 20.0_q_kg; // measured mass at fill_time
std::cout << "mp-units box example...\n";
std::cout << "fill height at " << fill_time << " = " << box.fill_level(measured_mass) << " ("
+8 -8
View File
@@ -36,22 +36,22 @@ int main()
std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
std::cout.precision(3);
constexpr auto C = 0.47q_uF;
constexpr auto V0 = 5.0q_V;
constexpr auto R = 4.7q_kR;
constexpr auto C = 0.47_q_uF;
constexpr auto V0 = 5.0_q_V;
constexpr auto R = 4.7_q_kR;
for (auto t = 0q_ms; t <= 50q_ms; ++t) {
for (auto t = 0_q_ms; t <= 50_q_ms; ++t) {
const Voltage auto Vt = V0 * units::exp(-t / (R * C));
std::cout << "at " << t << " voltage is ";
if (Vt >= 1q_V)
if (Vt >= 1_q_V)
std::cout << Vt;
else if (Vt >= 1q_mV)
else if (Vt >= 1_q_mV)
std::cout << quantity_cast<millivolt>(Vt);
else if (Vt >= 1q_uV)
else if (Vt >= 1_q_uV)
std::cout << quantity_cast<microvolt>(Vt);
else if (Vt >= 1q_nV)
else if (Vt >= 1_q_nV)
std::cout << quantity_cast<nanovolt>(Vt);
else
std::cout << quantity_cast<picovolt>(Vt);
+13 -13
View File
@@ -39,12 +39,12 @@ void simple_quantities()
using distance = length<metre>;
using duration = physical::si::time<second>;
constexpr distance km = 1.0q_km;
constexpr distance miles = 1.0q_mi;
constexpr distance km = 1.0_q_km;
constexpr distance miles = 1.0_q_mi;
constexpr duration sec = 1q_s;
constexpr duration min = 1q_min;
constexpr duration hr = 1q_h;
constexpr duration sec = 1_q_s;
constexpr duration min = 1_q_min;
constexpr duration hr = 1_q_h;
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";
@@ -61,14 +61,14 @@ void quantities_with_typed_units()
using namespace units::physical::si;
using namespace units::physical::international;
constexpr length<kilometre> km = 1.0q_km;
constexpr length<mile> miles = 1.0q_mi;
constexpr length<kilometre> km = 1.0_q_km;
constexpr length<mile> miles = 1.0_q_mi;
std::cout.precision(6);
constexpr si::time<second> sec = 1q_s;
constexpr si::time<minute> min = 1q_min;
constexpr si::time<hour> hr = 1q_h;
constexpr si::time<second> sec = 1_q_s;
constexpr si::time<minute> min = 1_q_min;
constexpr si::time<hour> hr = 1_q_h;
std::cout << "A more flexible option is to provide separate types for each unit,\n\n";
std::cout << km << '\n';
@@ -77,7 +77,7 @@ void quantities_with_typed_units()
std::cout << min << '\n';
std::cout << hr << "\n\n";
constexpr length<metre> meter = 1q_m;
constexpr length<metre> meter = 1_q_m;
std::cout << "then a wide range of pre-defined units can be defined and converted,\n"
" for consistency and repeatability across applications:\n\n";
@@ -111,8 +111,8 @@ void calcs_comparison()
"when adding two values of the same very big\n"
"or very small type:\n\n";
length<femtometre,float> L1A = 2.q_fm;
length<femtometre,float> L2A = 3.q_fm;
length<femtometre,float> L1A = 2._q_fm;
length<femtometre,float> L2A = 3._q_fm;
length<femtometre,float> LrA = L1A + L2A;
fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n",L1A,L2A,LrA);
+1 -1
View File
@@ -45,7 +45,7 @@ int main()
std::cout << "conversion factor in mp-units...\n\n";
constexpr length<metre> lengthA = 2.0q_m;
constexpr length<metre> lengthA = 2.0_q_m;
constexpr length<millimetre> lengthB = lengthA;
std::cout << fmt::format("lengthA( {} ) and lengthB( {} )\n", lengthA, lengthB)
+2 -2
View File
@@ -31,8 +31,8 @@ using namespace units::physical::si::literals;
int main()
{
auto torque = 20.0q_Nm;
auto energy = 20.0q_J;
auto torque = 20.0_q_Nm;
auto energy = 20.0_q_J;
physical::Angle auto angle = torque / energy;
+4 -4
View File
@@ -67,7 +67,7 @@ auto fmt_line(const Q a)
void print_details(std::string_view description, const Ship& ship)
{
using namespace units::physical::fps::literals;
const auto waterDensity = 62.4q_lb_per_ft3;
const auto waterDensity = 62.4_q_lb_per_ft3;
std::cout << fmt::format("{}\n", description);
std::cout << fmt::format("{:20} : {}\n", "length", fmt_line<fps::length<fps::yard>, si::length<si::metre>>(ship.length))
<< fmt::format("{:20} : {}\n", "draft", fmt_line<fps::length<fps::yard>, si::length<si::metre>>(ship.draft))
@@ -87,13 +87,13 @@ int main()
using namespace units::physical::fps::literals;
// KMS Bismark, using the units the Germans would use, taken from Wiki
auto bismark = Ship{.length{251.q_m}, .draft{9.3q_m}, .beam{36q_m}, .speed{56q_km_per_h}, .mass{50'300q_t}, .mainGuns{380q_mm}, .shellMass{800q_kg}, .shellSpeed{820.q_m_per_s}, .power{110.45q_kW}};
auto bismark = Ship{.length{251._q_m}, .draft{9.3_q_m}, .beam{36_q_m}, .speed{56_q_km_per_h}, .mass{50'300_q_t}, .mainGuns{380_q_mm}, .shellMass{800_q_kg}, .shellSpeed{820._q_m_per_s}, .power{110.45_q_kW}};
// USS Iowa, using units from the foot-pound-second system
auto iowa = Ship{.length{860.q_ft}, .draft{37.q_ft + 2.q_in}, .beam{108.q_ft + 2.q_in}, .speed{33q_knot}, .mass{57'540q_lton}, .mainGuns{16q_in}, .shellMass{2700q_lb}, .shellSpeed{2690.q_ft_per_s}, .power{212'000q_hp}};
auto iowa = Ship{.length{860._q_ft}, .draft{37._q_ft + 2._q_in}, .beam{108._q_ft + 2._q_in}, .speed{33_q_knot}, .mass{57'540_q_lton}, .mainGuns{16_q_in}, .shellMass{2700_q_lb}, .shellSpeed{2690._q_ft_per_s}, .power{212'000_q_hp}};
// HMS King George V, using units from the foot-pound-second system
auto kgv = Ship{.length{745.1q_ft}, .draft{33.q_ft + 7.5q_in}, .beam{103.2q_ft + 2.5q_in}, .speed{28.3q_knot}, .mass{42'245q_lton}, .mainGuns{14q_in}, .shellMass{1'590q_lb}, .shellSpeed{2483.q_ft_per_s}, .power{110'000q_hp}};
auto kgv = Ship{.length{745.1_q_ft}, .draft{33._q_ft + 7.5_q_in}, .beam{103.2_q_ft + 2.5_q_in}, .speed{28.3_q_knot}, .mass{42'245_q_lton}, .mainGuns{14_q_in}, .shellMass{1'590_q_lb}, .shellSpeed{2483._q_ft_per_s}, .power{110'000_q_hp}};
print_details("KMS Bismark, defined in appropriate units from the SI system", bismark);
std::cout << "\n\n";
+13 -13
View File
@@ -217,10 +217,10 @@ struct glider {
auto get_gliders()
{
const std::array gliders = {
glider{"SZD-30 Pirat", {velocity(83q_km_per_h), rate_of_climb(-0.7389q_m_per_s)}},
glider{"SZD-51 Junior", {velocity(80q_km_per_h), rate_of_climb(-0.6349q_m_per_s)}},
glider{"SZD-48 Jantar Std 3", {velocity(110q_km_per_h), rate_of_climb(-0.77355q_m_per_s)}},
glider{"SZD-56 Diana", {velocity(110q_km_per_h), rate_of_climb(-0.63657q_m_per_s)}}
glider{"SZD-30 Pirat", {velocity(83_q_km_per_h), rate_of_climb(-0.7389_q_m_per_s)}},
glider{"SZD-51 Junior", {velocity(80_q_km_per_h), rate_of_climb(-0.6349_q_m_per_s)}},
glider{"SZD-48 Jantar Std 3", {velocity(110_q_km_per_h), rate_of_climb(-0.77355_q_m_per_s)}},
glider{"SZD-56 Diana", {velocity(110_q_km_per_h), rate_of_climb(-0.63657_q_m_per_s)}}
};
return gliders;
}
@@ -258,9 +258,9 @@ struct weather {
auto get_weather_conditions()
{
const std::array weather_conditions = {
std::pair("Good", weather{height(1900q_m), rate_of_climb(4.3q_m_per_s)}),
std::pair("Medium", weather{height(1550q_m), rate_of_climb(2.8q_m_per_s)}),
std::pair("Bad", weather{height(850q_m), rate_of_climb(1.8q_m_per_s)})
std::pair("Good", weather{height(1900_q_m), rate_of_climb(4.3_q_m_per_s)}),
std::pair("Medium", weather{height(1550_q_m), rate_of_climb(2.8_q_m_per_s)}),
std::pair("Bad", weather{height(850_q_m), rate_of_climb(1.8_q_m_per_s)})
};
return weather_conditions;
}
@@ -462,7 +462,7 @@ void estimate(const glider& g, const weather& w, const task& t, const safety& s,
// circle in a thermall to gain height
point = circle(point, g, w, t, height_to_gain);
}
while(height_to_gain > height(0q_m));
while(height_to_gain > height(0_q_m));
// final glide
point = final_glide(point, g, t);
@@ -482,16 +482,16 @@ void example()
print(weather_conditions);
const task t = {
waypoint{"EPPR", altitude(16q_ft)},
waypoint{"EPGI", altitude(115q_ft)},
distance(81.7q_km)
waypoint{"EPPR", altitude(16_q_ft)},
waypoint{"EPGI", altitude(115_q_ft)},
distance(81.7_q_km)
};
print(t);
const safety s = {height(300q_m)};
const safety s = {height(300_q_m)};
print(s);
const aircraft_tow tow = {height(400q_m), rate_of_climb(1.6q_m_per_s)};
const aircraft_tow tow = {height(400_q_m), rate_of_climb(1.6_q_m_per_s)};
print(tow);
for(const auto& g : gliders) {
+1 -1
View File
@@ -35,7 +35,7 @@ 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 v1 = avg_speed(220_q_km, 2_q_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);
@@ -21,7 +21,7 @@ struct state_variable {
using namespace units::physical;
using namespace units::physical::si::literals;
constexpr auto radar_transmit_interval = 5.0q_s;
constexpr auto radar_transmit_interval = 5.0_q_s;
constexpr double kalman_range_gain = 0.2;
constexpr double kalman_speed_gain = 0.1;
@@ -52,16 +52,16 @@ int main()
std::cout << "\n\n1d aircraft α-β filter example2 from https://www.kalmanfilter.net/alphabeta.html#ex2";
std::cout << "\n\n";
constexpr auto measurements = std::array{0.0q_m, // N.B measurement[0] is unknown and unused
30110.0q_m, 30265.0q_m, 30740.0q_m, 30750.0q_m, 31135.0q_m,
31015.0q_m, 31180.0q_m, 31610.0q_m, 31960.0q_m, 31865.0q_m};
constexpr auto measurements = std::array{0.0_q_m, // N.B measurement[0] is unknown and unused
30110.0_q_m, 30265.0_q_m, 30740.0_q_m, 30750.0_q_m, 31135.0_q_m,
31015.0_q_m, 31180.0_q_m, 31610.0_q_m, 31960.0_q_m, 31865.0_q_m};
constexpr auto num_measurements = measurements.size();
std::array<state,num_measurements> track;
// We need an initial estimate of track[0] as there is no previous state to get a prediction from
track[0].range.estimated_current_state = 30'000q_m;
track[0].speed.estimated_current_state = 40.0q_m_per_s;
track[0].range.estimated_current_state = 30'000_q_m;
track[0].speed.estimated_current_state = 40.0_q_m_per_s;
for (auto n = 0U; n < num_measurements; ++n) {
if (n > 0) {
+28 -28
View File
@@ -68,9 +68,9 @@ void vector_of_quantity_add()
{
std::cout << "\nvector_of_quantity_add:\n";
vector<si::length<si::metre>> v = { 1q_m, 2q_m, 3q_m };
vector<si::length<si::metre>> u = { 3q_m, 2q_m, 1q_m };
vector<si::length<si::kilometre>> t = { 3q_km, 2q_km, 1q_km };
vector<si::length<si::metre>> v = { 1_q_m, 2_q_m, 3_q_m };
vector<si::length<si::metre>> u = { 3_q_m, 2_q_m, 1_q_m };
vector<si::length<si::kilometre>> t = { 3_q_km, 2_q_km, 1_q_km };
std::cout << "v = " << v << "\n";
std::cout << "u = " << u << "\n";
@@ -85,28 +85,28 @@ void vector_of_quantity_multiply_same()
{
std::cout << "\nvector_of_quantity_multiply_same:\n";
vector<si::length<si::metre>> v = { 1q_m, 2q_m, 3q_m };
vector<si::length<si::metre>> u = { 3q_m, 2q_m, 1q_m };
vector<si::length<si::metre>> v = { 1_q_m, 2_q_m, 3_q_m };
vector<si::length<si::metre>> u = { 3_q_m, 2_q_m, 1_q_m };
std::cout << "v = " << v << "\n";
std::cout << "u = " << u << "\n";
std::cout << "v * u = " << v * u << "\n";
std::cout << "2q_m * v = " << 2.q_m * v << "\n";
std::cout << "2_q_m * v = " << 2._q_m * v << "\n";
}
void vector_of_quantity_multiply_different()
{
std::cout << "\nvector_of_quantity_multiply_different:\n";
vector<si::force<si::newton>> v = { 1q_N, 2q_N, 3q_N };
vector<si::length<si::metre>> u = { 3q_m, 2q_m, 1q_m };
vector<si::force<si::newton>> v = { 1_q_N, 2_q_N, 3_q_N };
vector<si::length<si::metre>> u = { 3_q_m, 2_q_m, 1_q_m };
std::cout << "v = " << v << "\n";
std::cout << "u = " << u << "\n";
std::cout << "v * u = " << v * u << "\n";
std::cout << "2q_N * u = " << 2.q_N * u << "\n";
std::cout << "2_q_N * u = " << 2._q_N * u << "\n";
std::cout << "2 * u = " << 2 * u << "\n";
}
@@ -114,12 +114,12 @@ void vector_of_quantity_divide_by_scalar()
{
std::cout << "\nvector_of_quantity_divide_by_scalar:\n";
vector<si::length<si::metre>> v = { 4q_m, 8q_m, 12q_m };
vector<si::length<si::metre>> v = { 4_q_m, 8_q_m, 12_q_m };
std::cout << "v = " << v << "\n";
// TODO Uncomment when bug in the LA is fixed
// std::cout << "v / 2q_s = " << v / 2q_s << "\n";
// std::cout << "v / 2_q_s = " << v / 2_q_s << "\n";
// std::cout << "v / 2 = " << v / 2 << "\n";
}
@@ -135,9 +135,9 @@ void matrix_of_quantity_add()
{
std::cout << "\nmatrix_of_quantity_add:\n";
matrix<si::length<si::metre>> v = {{ 1q_m, 2q_m, 3q_m }, { 4q_m, 5q_m, 6q_m }, { 7q_m, 8q_m, 9q_m }};
matrix<si::length<si::metre>> u = {{ 3q_m, 2q_m, 1q_m }, { 3q_m, 2q_m, 1q_m }, { 3q_m, 2q_m, 1q_m }};
matrix<si::length<si::millimetre>> t = {{ 3q_mm, 2q_mm, 1q_mm }, { 3q_mm, 2q_mm, 1q_mm }, { 3q_mm, 2q_mm, 1q_mm }};
matrix<si::length<si::metre>> v = {{ 1_q_m, 2_q_m, 3_q_m }, { 4_q_m, 5_q_m, 6_q_m }, { 7_q_m, 8_q_m, 9_q_m }};
matrix<si::length<si::metre>> u = {{ 3_q_m, 2_q_m, 1_q_m }, { 3_q_m, 2_q_m, 1_q_m }, { 3_q_m, 2_q_m, 1_q_m }};
matrix<si::length<si::millimetre>> t = {{ 3_q_mm, 2_q_mm, 1_q_mm }, { 3_q_mm, 2_q_mm, 1_q_mm }, { 3_q_mm, 2_q_mm, 1_q_mm }};
std::cout << "v =\n" << v << "\n";
std::cout << "u =\n" << u << "\n";
@@ -154,28 +154,28 @@ void matrix_of_quantity_multiply_same()
{
std::cout << "\nmatrix_of_quantity_multiply_same:\n";
matrix<si::length<si::metre>> v = {{ 1q_m, 2q_m, 3q_m }, { 4q_m, 5q_m, 6q_m }, { 7q_m, 8q_m, 9q_m }};
vector<si::length<si::metre>> u = { 3q_m, 2q_m, 1q_m };
matrix<si::length<si::metre>> v = {{ 1_q_m, 2_q_m, 3_q_m }, { 4_q_m, 5_q_m, 6_q_m }, { 7_q_m, 8_q_m, 9_q_m }};
vector<si::length<si::metre>> u = { 3_q_m, 2_q_m, 1_q_m };
std::cout << "v =\n" << v << "\n";
std::cout << "u =\n" << u << "\n";
std::cout << "v * u =\n" << v * u << "\n";
std::cout << "2q_m * u =\n" << 2.q_m * u << "\n";
std::cout << "2_q_m * u =\n" << 2._q_m * u << "\n";
}
void matrix_of_quantity_multiply_different()
{
std::cout << "\nmatrix_of_quantity_multiply_different:\n";
vector<si::force<si::newton>> v = { 1q_N, 2q_N, 3q_N };
matrix<si::length<si::metre>> u = {{ 1q_m, 2q_m, 3q_m }, { 4q_m, 5q_m, 6q_m }, { 7q_m, 8q_m, 9q_m }};
vector<si::force<si::newton>> v = { 1_q_N, 2_q_N, 3_q_N };
matrix<si::length<si::metre>> u = {{ 1_q_m, 2_q_m, 3_q_m }, { 4_q_m, 5_q_m, 6_q_m }, { 7_q_m, 8_q_m, 9_q_m }};
std::cout << "v =\n" << v << "\n";
std::cout << "u =\n" << u << "\n";
std::cout << "v * u =\n" << v * u << "\n";
std::cout << "2q_N * u =\n" << 2.q_N * u << "\n";
std::cout << "2_q_N * u =\n" << 2._q_N * u << "\n";
std::cout << "2 * u =\n" << 2 * u << "\n";
}
@@ -183,12 +183,12 @@ void matrix_of_quantity_divide_by_scalar()
{
std::cout << "\nmatrix_of_quantity_divide_by_scalar:\n";
matrix<si::length<si::metre>> v = {{ 2q_m, 4q_m, 6q_m }, { 4q_m, 6q_m, 8q_m }, { 8q_m, 4q_m, 2q_m }};
matrix<si::length<si::metre>> v = {{ 2_q_m, 4_q_m, 6_q_m }, { 4_q_m, 6_q_m, 8_q_m }, { 8_q_m, 4_q_m, 2_q_m }};
std::cout << "v =\n" << v << "\n";
// TODO Uncomment when bug in the LA is fixed
// std::cout << "v / 2q_s =\n" << v / 2q_s << "\n";
// std::cout << "v / 2_q_s =\n" << v / 2_q_s << "\n";
// std::cout << "v / 2 =\n" << v / 2 << "\n";
}
@@ -234,7 +234,7 @@ void quantity_of_vector_multiply_same()
std::cout << "u = " << u << "\n";
std::cout << "v * u = " << v * u << "\n";
std::cout << "2q_m * v = " << 2.q_m * v << "\n";
std::cout << "2_q_m * v = " << 2._q_m * v << "\n";
}
void quantity_of_vector_multiply_different()
@@ -248,7 +248,7 @@ void quantity_of_vector_multiply_different()
std::cout << "u = " << u << "\n";
std::cout << "v * u = " << v * u << "\n";
std::cout << "2q_N * u = " << 2.q_N * u << "\n";
std::cout << "2_q_N * u = " << 2._q_N * u << "\n";
std::cout << "2 * u = " << 2 * u << "\n";
}
@@ -261,7 +261,7 @@ void quantity_of_vector_divide_by_scalar()
std::cout << "v = " << v << "\n";
// TODO Uncomment when bug in the LA is fixed
// std::cout << "v / 2q_s = " << v / 2q_s << "\n";
// std::cout << "v / 2_q_s = " << v / 2_q_s << "\n";
// std::cout << "v / 2 = " << v / 2 << "\n";
}
@@ -306,7 +306,7 @@ void quantity_of_matrix_multiply_same()
std::cout << "u =\n" << u << "\n";
std::cout << "v * u =\n" << v * u << "\n";
std::cout << "2q_m * u =\n" << 2.q_m * u << "\n";
std::cout << "2_q_m * u =\n" << 2._q_m * u << "\n";
}
void quantity_of_matrix_multiply_different()
@@ -320,7 +320,7 @@ void quantity_of_matrix_multiply_different()
std::cout << "u =\n" << u << "\n";
std::cout << "v * u =\n" << v * u << "\n";
std::cout << "2q_N * u =\n" << 2.q_N * u << "\n";
std::cout << "2_q_N * u =\n" << 2._q_N * u << "\n";
std::cout << "2 * u =\n" << 2 * u << "\n";
}
@@ -333,7 +333,7 @@ void quantity_of_matrix_divide_by_scalar()
std::cout << "v =\n" << v << "\n";
// TODO Uncomment when bug in the LA is fixed
// std::cout << "v / 2q_s =\n" << v / 2q_s << "\n";
// std::cout << "v / 2_q_s =\n" << v / 2_q_s << "\n";
// std::cout << "v / 2 =\n" << v / 2 << "\n";
}
+2 -2
View File
@@ -46,8 +46,8 @@ void si_example()
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 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"
+5 -5
View File
@@ -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;
Length auto d1 = 123_q_m;
Time auto t1 = 10_q_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;
auto temp1 = v1 * 50_q_m; // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
Speed auto v2 = temp1 / 100_q_m; // back to known dimensions again
Length auto d2 = v2 * 60_q_s;
std::cout << "d1 = " << d1 << '\n';
std::cout << "t1 = " << t1 << '\n';