// The MIT License (MIT) // // Copyright (c) 2018 Mateusz Pusz // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace units::isq; // Some basic specs for the warship struct Ship { si::fps::length length; si::fps::length draft; si::fps::length beam; si::fps::speed speed; si::fps::mass mass; si::fps::length mainGuns; si::fps::mass shellMass; si::fps::speed shellSpeed; si::fps::power power; }; // Print 'a' in its current units and print its value cast to the units in each of Args template auto fmt_line(const Q a) { return fmt::format("{:22}", a) + (fmt::format(",{:20}", units::quantity_cast(a)) + ...); } // Print the ship details in the units as defined in the Ship struct, in other si::imperial units, and in SI void print_details(std::string_view description, const Ship& ship) { using namespace units::isq::si::fps::literals; const auto waterDensity = 62.4_q_lb_per_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)); } int main() { using namespace units::isq::si::literals; using namespace units::isq::si::fps::literals; // KMS Bismark, using the units the Germans would use, taken from Wiki 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{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.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"; print_details("USS Iowa, defined in appropriate units foot-pound-second system", iowa); std::cout << "\n\n"; print_details("HMS King George V, defined in appropriate units foot-pound-second system", kgv); }