refactor: systems defined in terms of SI moved under si namespace

This commit is contained in:
Mateusz Pusz committed 2020-09-10 17:14:33 +02:00
1 parent 7d204a1177
commit 79558a6d72
124 files changed
+580 -587

No files matched your search

@@ -25,7 +25,7 @@
#include "./units_str.h"
using namespace units::physical::si::literals;
using namespace units::physical::international;
using namespace units::physical::si::international;
using namespace units::experimental;
void simple_quantities()
+22 -22
View File
@@ -3,11 +3,11 @@
#pragma once
#include <units/physical/si/length.h>
#include <units/physical/imperial/length.h>
#include <units/physical/international/length.h>
#include <units/physical/typographic/length.h>
#include <units/physical/us/length.h>
#include <units/physical/iau/length.h>
#include <units/physical/si/imperial/length.h>
#include <units/physical/si/international/length.h>
#include <units/physical/si/typographic/length.h>
#include <units/physical/si/us/length.h>
#include <units/physical/si/iau/length.h>
namespace units{
namespace experimental{
@@ -30,55 +30,55 @@ template<typename Rep = double>
using AU = units::physical::si::length<units::physical::si::astronomical_unit, Rep>;
template<typename Rep = double>
using in = units::physical::si::length<units::physical::international::inch, Rep>;
using in = units::physical::si::length<units::physical::si::international::inch, Rep>;
template<typename Rep = double>
using angstrom = units::physical::si::length<units::physical::iau::angstrom, Rep>;
using angstrom = units::physical::si::length<units::physical::si::iau::angstrom, Rep>;
template<typename Rep = double>
using ch = units::physical::si::length<units::physical::imperial::chain, Rep>;
using ch = units::physical::si::length<units::physical::si::imperial::chain, Rep>;
template<typename Rep = double>
using fathom = units::physical::si::length<units::physical::international::fathom, Rep>;
using fathom = units::physical::si::length<units::physical::si::international::fathom, Rep>;
template<typename Rep = double>
using fathom_us = units::physical::si::length<units::physical::us::fathom, Rep>;
using fathom_us = units::physical::si::length<units::physical::si::us::fathom, Rep>;
template<typename Rep = double>
using ft = units::physical::si::length<units::physical::international::foot, Rep>;
using ft = units::physical::si::length<units::physical::si::international::foot, Rep>;
template<typename Rep = double>
using ft_us = units::physical::si::length<units::physical::us::foot, Rep>;
using ft_us = units::physical::si::length<units::physical::si::us::foot, Rep>;
template<typename Rep = double>
using ly = units::physical::si::length<units::physical::iau::light_year, Rep>;
using ly = units::physical::si::length<units::physical::si::iau::light_year, Rep>;
template<typename Rep = double>
using mi = units::physical::si::length<units::physical::international::mile, Rep>;
using mi = units::physical::si::length<units::physical::si::international::mile, Rep>;
template<typename Rep = double>
using mi_naut = units::physical::si::length<units::physical::international::nautical_mile, Rep>;
using mi_naut = units::physical::si::length<units::physical::si::international::nautical_mile, Rep>;
template<typename Rep = double>
using pc = units::physical::si::length<units::physical::iau::parsec, Rep>;
using pc = units::physical::si::length<units::physical::si::iau::parsec, Rep>;
template<typename Rep = double>
using pica_comp = units::physical::si::length<units::physical::typographic::pica_comp, Rep>;
using pica_comp = units::physical::si::length<units::physical::si::typographic::pica_comp, Rep>;
template<typename Rep = double>
using pica_prn = units::physical::si::length<units::physical::typographic::pica_prn, Rep>;
using pica_prn = units::physical::si::length<units::physical::si::typographic::pica_prn, Rep>;
template<typename Rep = double>
using point_comp = units::physical::si::length<units::physical::typographic::point_comp, Rep>;
using point_comp = units::physical::si::length<units::physical::si::typographic::point_comp, Rep>;
template<typename Rep = double>
using point_prn = units::physical::si::length<units::physical::typographic::point_prn, Rep>;
using point_prn = units::physical::si::length<units::physical::si::typographic::point_prn, Rep>;
template<typename Rep = double>
using rd = units::physical::si::length<units::physical::imperial::rod, Rep>;
using rd = units::physical::si::length<units::physical::si::imperial::rod, Rep>;
template<typename Rep = double>
using yd = units::physical::si::length<units::physical::international::yard, Rep>;
using yd = units::physical::si::length<units::physical::si::international::yard, Rep>;
} // namespace length
+8 -8
View File
@@ -20,9 +20,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/physical/cgs/speed.h>
#include <units/physical/si/cgs/speed.h>
#include <units/physical/si/international/speed.h>
#include <units/physical/si/speed.h>
#include <units/physical/international/speed.h>
#include <iostream>
namespace {
@@ -97,7 +97,7 @@ void example()
// Customary Units (int)
{
using namespace units::physical::international::literals;
using namespace units::physical::si::international::literals;
constexpr Length auto distance = 140_q_mi; // constructed from a UDL
constexpr si::time<si::hour, int> duration(2); // constructed from a value
@@ -113,7 +113,7 @@ void example()
// Customary Units (double)
{
using namespace units::physical::international::literals;
using namespace units::physical::si::international::literals;
constexpr Length auto distance = 140._q_mi; // constructed from a UDL
constexpr si::time<si::hour> duration(2); // constructed from a value
@@ -131,9 +131,9 @@ void example()
// CGS (int)
{
using namespace units::physical::cgs::literals;
using namespace units::physical::si::cgs::literals;
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
constexpr si::cgs::time<si::hour, int> duration(2); // constructed from a value
std::cout << "\nCGS units with 'int' as representation\n";
@@ -150,9 +150,9 @@ void example()
// CGS (double)
{
using namespace units::physical::cgs::literals;
using namespace units::physical::si::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 si::cgs::time<si::hour> duration(2); // constructed from a value
std::cout << "\nCGS units with 'double' as representation\n";
+25 -25
View File
@@ -15,16 +15,16 @@
along with this program. If not, see http://www.gnu.org/licenses./
*/
#include <units/physical/iau/length.h>
#include <units/physical/imperial/length.h>
#include <units/physical/international/length.h>
#include <units/format.h>
#include <units/physical/si/area.h>
#include <units/physical/si/iau/length.h>
#include <units/physical/si/imperial/length.h>
#include <units/physical/si/international/length.h>
#include <units/physical/si/length.h>
#include <units/physical/si/time.h>
#include <units/physical/si/typographic/length.h>
#include <units/physical/si/us/length.h>
#include <units/physical/si/volume.h>
#include <units/physical/typographic/length.h>
#include <units/physical/us/length.h>
#include <units/format.h>
#include <iostream>
namespace {
@@ -34,7 +34,7 @@ using namespace units;
void simple_quantities()
{
using namespace units::physical::si;
using namespace units::physical::international;
using namespace units::physical::si::international;
using distance = length<metre>;
using duration = physical::si::time<second>;
@@ -59,7 +59,7 @@ void quantities_with_typed_units()
{
using namespace units::physical;
using namespace units::physical::si;
using namespace units::physical::international;
using namespace units::physical::si::international;
constexpr length<kilometre> km = 1.0_q_km;
constexpr length<mile> miles = 1.0_q_mi;
@@ -84,23 +84,23 @@ void quantities_with_typed_units()
std::cout << meter << '\n';
std::cout << " = " << quantity_cast<si::astronomical_unit>(meter) << '\n';
std::cout << " = " << quantity_cast<iau::angstrom>(meter) << '\n';
std::cout << " = " << quantity_cast<imperial::chain>(meter) << '\n';
std::cout << " = " << quantity_cast<international::fathom>(meter) << '\n';
std::cout << " = " << quantity_cast<us::fathom>(meter) << '\n';
std::cout << " = " << quantity_cast<international::foot>(meter) << '\n';
std::cout << " = " << quantity_cast<us::foot>(meter) << '\n';
std::cout << " = " << quantity_cast<international::inch>(meter) << '\n';
std::cout << " = " << quantity_cast<iau::light_year>(meter) << '\n';
std::cout << " = " << quantity_cast<international::mile>(meter) << '\n';
std::cout << " = " << quantity_cast<international::nautical_mile>(meter) << '\n';
std::cout << " = " << quantity_cast<iau::parsec>(meter) << '\n';
std::cout << " = " << quantity_cast<typographic::pica_comp>(meter) << '\n';
std::cout << " = " << quantity_cast<typographic::pica_prn>(meter) << '\n';
std::cout << " = " << quantity_cast<typographic::point_comp>(meter) << '\n';
std::cout << " = " << quantity_cast<typographic::point_prn>(meter) << '\n';
std::cout << " = " << quantity_cast<imperial::rod>(meter) << '\n';
std::cout << " = " << quantity_cast<international::yard>(meter) << '\n';
std::cout << " = " << quantity_cast<si::iau::angstrom>(meter) << '\n';
std::cout << " = " << quantity_cast<si::imperial::chain>(meter) << '\n';
std::cout << " = " << quantity_cast<si::international::fathom>(meter) << '\n';
std::cout << " = " << quantity_cast<si::us::fathom>(meter) << '\n';
std::cout << " = " << quantity_cast<si::international::foot>(meter) << '\n';
std::cout << " = " << quantity_cast<si::us::foot>(meter) << '\n';
std::cout << " = " << quantity_cast<si::international::inch>(meter) << '\n';
std::cout << " = " << quantity_cast<si::iau::light_year>(meter) << '\n';
std::cout << " = " << quantity_cast<si::international::mile>(meter) << '\n';
std::cout << " = " << quantity_cast<si::international::nautical_mile>(meter) << '\n';
std::cout << " = " << quantity_cast<si::iau::parsec>(meter) << '\n';
std::cout << " = " << quantity_cast<si::typographic::pica_comp>(meter) << '\n';
std::cout << " = " << quantity_cast<si::typographic::pica_prn>(meter) << '\n';
std::cout << " = " << quantity_cast<si::typographic::point_comp>(meter) << '\n';
std::cout << " = " << quantity_cast<si::typographic::point_prn>(meter) << '\n';
std::cout << " = " << quantity_cast<si::imperial::rod>(meter) << '\n';
std::cout << " = " << quantity_cast<si::international::yard>(meter) << '\n';
}
void calcs_comparison()
+28 -30
View File
@@ -20,22 +20,20 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/concepts.h>
#include <units/format.h>
#include <units/physical/fps/density.h>
#include <units/physical/fps/length.h>
#include <units/physical/fps/mass.h>
#include <units/physical/fps/power.h>
#include <units/physical/fps/speed.h>
#include <units/physical/fps/volume.h>
#include <units/physical/si/fps/density.h>
#include <units/physical/si/fps/length.h>
#include <units/physical/si/fps/mass.h>
#include <units/physical/si/fps/power.h>
#include <units/physical/si/fps/speed.h>
#include <units/physical/si/fps/volume.h>
#include <units/physical/si/length.h>
#include <units/physical/si/mass.h>
#include <units/physical/si/power.h>
#include <units/physical/si/speed.h>
#include <units/physical/si/volume.h>
#include <units/concepts.h>
#include <units/quantity.h>
#include <iostream>
using namespace units::physical;
@@ -43,17 +41,17 @@ using namespace units::physical;
// Some basic specs for the warship
struct Ship {
fps::length<fps::foot> length;
fps::length<fps::foot> draft;
fps::length<fps::foot> beam;
si::fps::length<si::fps::foot> length;
si::fps::length<si::fps::foot> draft;
si::fps::length<si::fps::foot> beam;
fps::speed<fps::foot_per_second> speed;
fps::mass<fps::pound> mass;
si::fps::speed<si::fps::foot_per_second> speed;
si::fps::mass<si::fps::pound> mass;
fps::length<fps::inch> mainGuns;
fps::mass<fps::pound> shellMass;
fps::speed<fps::foot_per_second> shellSpeed;
fps::power<fps::foot_poundal_per_second> power;
si::fps::length<si::fps::inch> mainGuns;
si::fps::mass<si::fps::pound> shellMass;
si::fps::speed<si::fps::foot_per_second> shellSpeed;
si::fps::power<si::fps::foot_poundal_per_second> power;
};
// Print 'a' in its current units and print its value cast to the units in each of Args
@@ -63,28 +61,28 @@ auto fmt_line(const Q a)
return fmt::format("{:22}", a) + (fmt::format(",{:20}", units::quantity_cast<Args>(a)) + ...);
}
// Print the ship details in the units as defined in the Ship struct, in other imperial units, and in SI
// 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::physical::fps::literals;
using namespace units::physical::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<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))
<< fmt::format("{:20} : {}\n", "beam", fmt_line<fps::length<fps::yard>, si::length<si::metre>>(ship.beam))
<< fmt::format("{:20} : {}\n", "mass", fmt_line<fps::mass<fps::long_ton>, si::mass<si::tonne>>(ship.mass))
<< fmt::format("{:20} : {}\n", "speed", fmt_line<fps::speed<fps::knot>, si::speed<si::kilometre_per_hour>>(ship.speed))
<< fmt::format("{:20} : {}\n", "power", fmt_line<fps::power<fps::horse_power>, si::power<si::kilowatt>>(ship.power))
<< fmt::format("{:20} : {}\n", "main guns", fmt_line<fps::length<fps::inch>, si::length<si::millimetre>>(ship.mainGuns))
<< fmt::format("{:20} : {}\n", "fire shells weighing",fmt_line<fps::mass<fps::long_ton>, si::mass<si::kilogram>>(ship.shellMass))
<< fmt::format("{:20} : {}\n", "fire shells at",fmt_line<fps::speed<fps::mile_per_hour>, si::speed<si::kilometre_per_hour>>(ship.shellSpeed))
std::cout << fmt::format("{:20} : {}\n", "length", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.length))
<< fmt::format("{:20} : {}\n", "draft", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.draft))
<< fmt::format("{:20} : {}\n", "beam", fmt_line<si::fps::length<si::fps::yard>, si::length<si::metre>>(ship.beam))
<< fmt::format("{:20} : {}\n", "mass", fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::tonne>>(ship.mass))
<< fmt::format("{:20} : {}\n", "speed", fmt_line<si::fps::speed<si::fps::knot>, si::speed<si::kilometre_per_hour>>(ship.speed))
<< fmt::format("{:20} : {}\n", "power", fmt_line<si::fps::power<si::fps::horse_power>, si::power<si::kilowatt>>(ship.power))
<< fmt::format("{:20} : {}\n", "main guns", fmt_line<si::fps::length<si::fps::inch>, si::length<si::millimetre>>(ship.mainGuns))
<< fmt::format("{:20} : {}\n", "fire shells weighing",fmt_line<si::fps::mass<si::fps::long_ton>, si::mass<si::kilogram>>(ship.shellMass))
<< 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))
<< fmt::format("{:20} : {}\n", "volume underwater", fmt_line<si::volume<si::cubic_metre>, si::volume<si::litre>>(ship.mass / waterDensity));
}
int main()
{
using namespace units::physical::si::literals;
using namespace units::physical::fps::literals;
using namespace units::physical::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}};
+5 -5
View File
@@ -20,14 +20,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/physical/si/speed.h>
#include <units/physical/international/length.h>
#include <units/math.h>
#include <units/format.h>
#include <units/math.h>
#include <units/physical/si/international/length.h>
#include <units/physical/si/speed.h>
#include <units/quantity_point.h>
#include <array>
#include <iostream>
#include <compare>
#include <iostream>
// horizontal/vertical vector
namespace {
@@ -202,7 +202,7 @@ struct fmt::formatter<altitude> : formatter<si::length<si::metre>> {
namespace {
using namespace units::physical::si::literals;
using namespace units::physical::international::literals;
using namespace units::physical::si::international::literals;
struct glider {
struct polar_point {
+3 -3
View File
@@ -20,9 +20,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/physical/si/speed.h>
#include <units/physical/international/speed.h>
#include <units/format.h>
#include <units/physical/si/international/speed.h>
#include <units/physical/si/speed.h>
#include <iostream>
using namespace units::physical;
@@ -36,7 +36,7 @@ int main()
{
using namespace units::physical::si::literals;
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 v2 = avg_speed(si::length<si::international::mile>(140), si::time<si::hour>(2));
#if DOWNCAST_MODE == 0
Speed auto v3 = quantity_cast<si::dim_speed, si::metre_per_second>(v2);
#else