diff --git a/example/references/avg_speed.cpp b/example/references/avg_speed.cpp index 4b03a180..aba1123e 100644 --- a/example/references/avg_speed.cpp +++ b/example/references/avg_speed.cpp @@ -74,8 +74,8 @@ void example() // SI (int) { using namespace units::isq::si::references; - constexpr Length auto distance = 220 * km; // constructed from a reference - constexpr si::time duration(2); // constructed from a value + constexpr auto distance = 220 * km; + constexpr auto duration = 2 * h; std::cout << "SI units with 'int' as representation\n"; @@ -88,8 +88,8 @@ void example() // SI (double) { using namespace units::isq::si::references; - constexpr Length auto distance = 220. * km; // constructed from a reference - constexpr si::time duration(2); // constructed from a value + constexpr auto distance = 220. * km; + constexpr auto duration = 2. * h; std::cout << "\nSI units with 'double' as representation\n"; @@ -103,9 +103,10 @@ void example() // Customary Units (int) { - using namespace units::isq::si::international::references; - constexpr Length auto distance = 140 * mi; // constructed from a reference - constexpr si::time duration(2); // constructed from a value + using namespace units::isq::si::time_references; + using namespace units::isq::si::international::length_references; + constexpr auto distance = 140 * mi; + constexpr auto duration = 2 * h; std::cout << "\nUS Customary Units with 'int' as representation\n"; @@ -119,9 +120,10 @@ void example() // Customary Units (double) { - using namespace units::isq::si::international::references; - constexpr Length auto distance = 140. * mi; // constructed from a reference - constexpr si::time duration(2); // constructed from a value + using namespace units::isq::si::time_references; + using namespace units::isq::si::international::length_references; + constexpr auto distance = 140. * mi; + constexpr auto duration = 2. * h; std::cout << "\nUS Customary Units with 'double' as representation\n"; @@ -137,9 +139,10 @@ void example() // CGS (int) { - using namespace units::isq::si::cgs::references; - constexpr Length auto distance = 22'000'000 * cm; // constructed from a reference - constexpr si::cgs::time duration(2); // constructed from a value + using namespace units::isq::si::time_references; + using namespace units::isq::si::cgs::length_references; + constexpr auto distance = 22'000'000 * cm; + constexpr auto duration = 2 * h; std::cout << "\nCGS units with 'int' as representation\n"; @@ -156,9 +159,10 @@ void example() // CGS (double) { - using namespace units::isq::si::cgs::references; - constexpr Length auto distance = 22'000'000. * cm; // constructed from a reference - constexpr si::cgs::time duration(2); // constructed from a value + using namespace units::isq::si::time_references; + using namespace units::isq::si::cgs::length_references; + constexpr auto distance = 22'000'000. * cm; + constexpr auto duration = 2. * h; std::cout << "\nCGS units with 'double' as representation\n"; diff --git a/example/references/box_example.cpp b/example/references/box_example.cpp index facf6d8f..c4ad8d95 100644 --- a/example/references/box_example.cpp +++ b/example/references/box_example.cpp @@ -82,10 +82,11 @@ public: int main() { using namespace units; - using namespace si::length_references; - using namespace si::time_references; + using namespace units::isq::si; + using namespace length_references; + using namespace time_references; - const si::length height = 200.0 * mm; + const auto height = quantity_cast(200.0 * mm); auto box = Box(1000.0 * mm, 500.0 * mm, height); box.set_contents_density(1000.0 * (kg / m3)); diff --git a/example/references/clcpp_response.cpp b/example/references/clcpp_response.cpp index 2d3516d3..704bbbb9 100644 --- a/example/references/clcpp_response.cpp +++ b/example/references/clcpp_response.cpp @@ -60,14 +60,14 @@ void quantities_with_typed_units() using namespace units::isq::si::references; using namespace units::isq::si::international::references; - constexpr si::length kilometers = 1.0 * km; - constexpr si::length miles = 1.0 * mi; + constexpr auto kilometers = 1.0 * km; + constexpr auto miles = 1.0 * mi; std::cout.precision(6); - constexpr si::time seconds = 1 * s; - constexpr si::time minutes = 1 * min; - constexpr si::time hours = 1 * h; + constexpr auto seconds = 1 * s; + constexpr auto minutes = 1 * min; + constexpr auto hours = 1 * h; std::cout << "A more flexible option is to provide separate types for each unit,\n\n"; std::cout << kilometers << '\n'; @@ -76,7 +76,7 @@ void quantities_with_typed_units() std::cout << minutes << '\n'; std::cout << hours << "\n\n"; - constexpr si::length meter = 1 * m; + constexpr auto meter = 1 * 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,28 +111,28 @@ void calcs_comparison() "when adding two values of the same very big\n" "or very small type:\n\n"; - si::length L1A = 2. * fm; - si::length L2A = 3. * fm; - si::length LrA = L1A + L2A; + const auto L1A = 2.f * fm; + const auto L2A = 3.f * fm; + const Length auto LrA = L1A + L2A; fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1A, L2A, LrA); std::cout << "The single unit method must convert large\n" "or small values in other units to the base unit.\n" "This is both inefficient and inaccurate\n\n"; - si::length L1B = L1A; - si::length L2B = L2A; - si::length LrB = L1B + L2B; + const auto L1B = quantity_cast(L1A); + const auto L2B = quantity_cast(L2A); + const Length auto LrB = L1B + L2B; fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1B, L2B, LrB); std::cout << "In multiplication and division:\n\n"; - si::area ArA = L1A * L2A; + const Area auto ArA = L1A * L2A; fmt::print("{:%.30Q %q}\n * {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1A, L2A, ArA); std::cout << "similar problems arise\n\n"; - si::area ArB = L1B * L2B; + const Area auto ArB = L1B * L2B; fmt::print("{:%.30Q %q}\n * {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1B, L2B, ArB); } diff --git a/example/references/conversion_factor.cpp b/example/references/conversion_factor.cpp index 436242ec..ef6eb7fc 100644 --- a/example/references/conversion_factor.cpp +++ b/example/references/conversion_factor.cpp @@ -47,8 +47,8 @@ int main() std::cout << "conversion factor in mp-units...\n\n"; - constexpr length lengthA = 2.0 * m; - constexpr length lengthB = lengthA; + constexpr auto lengthA = 2.0 * m; + constexpr auto lengthB = quantity_cast(lengthA); std::cout << fmt::format("lengthA( {} ) and lengthB( {} )\n", lengthA, lengthB) << "represent the same length in different units.\n\n"; diff --git a/example/references/foot_pound_second.cpp b/example/references/foot_pound_second.cpp index 4b8b8385..59edbef8 100644 --- a/example/references/foot_pound_second.cpp +++ b/example/references/foot_pound_second.cpp @@ -67,16 +67,16 @@ 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 << fmt::format("{}\n", description); - std::cout << fmt::format("{:20} : {}\n", "length", fmt_line, si::length>(ship.length)) - << fmt::format("{:20} : {}\n", "draft", fmt_line, si::length>(ship.draft)) - << fmt::format("{:20} : {}\n", "beam", fmt_line, si::length>(ship.beam)) - << fmt::format("{:20} : {}\n", "mass", fmt_line, si::mass>(ship.mass)) - << fmt::format("{:20} : {}\n", "speed", fmt_line, si::speed>(ship.speed)) - << fmt::format("{:20} : {}\n", "power", fmt_line, si::power>(ship.power)) - << fmt::format("{:20} : {}\n", "main guns", fmt_line, si::length>(ship.mainGuns)) - << fmt::format("{:20} : {}\n", "fire shells weighing",fmt_line, si::mass>(ship.shellMass)) - << fmt::format("{:20} : {}\n", "fire shells at",fmt_line, si::speed>(ship.shellSpeed)) - << fmt::format("{:20} : {}\n", "volume underwater", fmt_line, si::volume>(ship.mass / waterDensity)); + std::cout << fmt::format("{:20} : {}\n", "length", fmt_line, si::length>(ship.length)) + << fmt::format("{:20} : {}\n", "draft", fmt_line, si::length>(ship.draft)) + << fmt::format("{:20} : {}\n", "beam", fmt_line, si::length>(ship.beam)) + << fmt::format("{:20} : {}\n", "mass", fmt_line, si::mass>(ship.mass)) + << fmt::format("{:20} : {}\n", "speed", fmt_line, si::speed>(ship.speed)) + << fmt::format("{:20} : {}\n", "power", fmt_line, si::power>(ship.power)) + << fmt::format("{:20} : {}\n", "main guns", fmt_line, si::length>(ship.mainGuns)) + << fmt::format("{:20} : {}\n", "fire shells weighing", fmt_line, si::mass>(ship.shellMass)) + << fmt::format("{:20} : {}\n", "fire shells at", fmt_line, si::speed>(ship.shellSpeed)) + << fmt::format("{:20} : {}\n", "volume underwater", fmt_line, si::volume>(ship.mass / waterDensity)); } int main()