diff --git a/example/avg_velocity.cpp b/example/avg_velocity.cpp index 1127e9a3..74a09259 100644 --- a/example/avg_velocity.cpp +++ b/example/avg_velocity.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include namespace { diff --git a/example/box_example.cpp b/example/box_example.cpp index ed2820ed..bc8fcb0f 100644 --- a/example/box_example.cpp +++ b/example/box_example.cpp @@ -56,26 +56,26 @@ namespace{ struct Box{ - Box(length::m<> const& l, - length::m<> const& w, - length::m<> const& h + Box(const length::m<> & l, + const length::m<> & w, + const length::m<> & h ): length{l},width{w},height{h}{} force::N<> filled_weight()const { - volume::m3<> const volume + const volume::m3<> volume = length * width * height; - mass::kg<> const mass = contents.density * volume; + const mass::kg<> mass = contents.density * volume; return mass * acceleration::g<>; } - length::m<> fill_level(mass::kg<> const & measured_mass)const + length::m<> fill_level(const mass::kg<> & measured_mass)const { return height * (measured_mass * acceleration::g<>) / filled_weight(); } - volume::m3<> spare_capacity(mass::kg<> const & measured_mass)const + volume::m3<> spare_capacity(const mass::kg<> & measured_mass)const { return (height - fill_level(measured_mass)) * width * length; } @@ -85,7 +85,7 @@ struct Box{ density::kgpm3<> density; }contents; - void set_contents_density(density::kgpm3<> const & density_in) + void set_contents_density(const density::kgpm3<> & density_in) { assert( density_in > air_density ); contents.density = density_in; diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp index 3f30b8a4..dc48c9d9 100644 --- a/example/capacitor_time_curve.cpp +++ b/example/capacitor_time_curve.cpp @@ -56,13 +56,13 @@ int main() std::cout.setf(std::ios_base::fixed,std::ios_base::floatfield); std::cout.precision(3); - auto constexpr C = 0.47uF; - auto constexpr V0 = 5.0V; - auto constexpr R = 4.7kR; + constexpr auto C = 0.47uF; + constexpr auto V0 = 5.0V; + constexpr auto R = 4.7kR; for ( auto t = 0ms ; t <= 50ms; ++t ){ - auto const Vt = V0 * std::exp(-t / (R * C)); + const auto Vt = V0 * std::exp(-t / (R * C)); std::cout << "at " << t << " voltage is " ; diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index 3414caeb..23f2a41d 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -128,12 +128,13 @@ void simple_quantities() { using distance = length::m<>; using time = time::s<>; - distance constexpr km = 1.0km; - distance constexpr miles = 1.0mi; - time constexpr sec = 1s; - time constexpr min = 1min; - time constexpr hr = 1h; + constexpr distance km = 1.0km; + constexpr distance miles = 1.0mi; + + constexpr time sec = 1s; + constexpr time min = 1min; + constexpr time hr = 1h; 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"; @@ -146,15 +147,14 @@ void simple_quantities() void quantities_with_typed_units() { - length::km<> constexpr km = 1km; - - length::mi<> constexpr miles = 1.0mi; + constexpr length::km<> km = 1km; + constexpr length::mi<> miles = 1.0mi; std::cout.precision(6); - time::s<> constexpr sec = 1s; - time::min<> constexpr min = 1min; - time::h<> constexpr hr = 1h; + constexpr time::s<> sec = 1s; + constexpr time::min<> min = 1min; + constexpr time::h<> hr = 1h; std::cout << "A more flexible option is to provide separate types for each unit,\n\n"; std::cout << km << '\n'; @@ -163,7 +163,7 @@ void quantities_with_typed_units() std::cout << min << '\n'; std::cout << hr << "\n\n"; - length::m<> constexpr meter = 1m; + constexpr length::m<> meter = 1m; std::cout << "then a wide range of pre-defined units can be defined and converted,\n" " for consistency and repeatability across applications:\n\n"; diff --git a/example/conversion_factor.cpp b/example/conversion_factor.cpp index efc1bb1d..c69117f4 100644 --- a/example/conversion_factor.cpp +++ b/example/conversion_factor.cpp @@ -48,7 +48,7 @@ namespace { } // get at the units text of the quantity, without its numeric value - auto inline constexpr units_str( units::Quantity const & q) + auto inline constexpr units_str( const units::Quantity & q) { typedef std::remove_cvref_t qtype; return units::detail::unit_text(); @@ -74,8 +74,8 @@ int main() { std::cout << "conversion factor in mpusz/units...\n\n"; - length::m<> constexpr lengthA = 2.0m; - length::mm<> constexpr lengthB = lengthA; + constexpr length::m<> lengthA = 2.0m; + constexpr length::mm<> lengthB = lengthA; std::cout << "lengthA( " << lengthA << " ) and lengthB( " << lengthB << " )\n" "represent the same length in different units.\n\n"; diff --git a/example/hello_units.cpp b/example/hello_units.cpp index c90a6b8b..5aa8b5e4 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -21,7 +21,7 @@ // SOFTWARE. #include -#include +#include #include #include diff --git a/src/include/units/physical/iau/length.h b/src/include/units/physical/iau/length.h index bdf7986d..fd7a92b7 100644 --- a/src/include/units/physical/iau/length.h +++ b/src/include/units/physical/iau/length.h @@ -27,9 +27,9 @@ namespace units::iau { -struct light_year : named_scaled_unit,si::metre> {}; -struct parsec : named_scaled_unit,si::metre> {}; -struct angstrom : named_scaled_unit,si::metre> {}; +struct light_year : named_scaled_unit,si::metre> {}; +struct parsec : named_scaled_unit,si::metre> {}; +struct angstrom : named_scaled_unit,si::metre> {}; inline namespace literals { diff --git a/src/include/units/physical/us/area.h b/src/include/units/physical/international/area.h similarity index 95% rename from src/include/units/physical/us/area.h rename to src/include/units/physical/international/area.h index 713afcc4..9ed8f0d1 100644 --- a/src/include/units/physical/us/area.h +++ b/src/include/units/physical/international/area.h @@ -25,7 +25,7 @@ #include #include -namespace units::us { +namespace units::international { struct square_foot : deduced_unit {}; @@ -37,4 +37,4 @@ constexpr auto operator"" ft2(long double l) { return si::area, si::metre> {}; - //international foot //https://en.wikipedia.org/wiki/Foot_(unit)#International_foot struct foot : named_scaled_unit, si::metre> {}; @@ -55,10 +54,9 @@ struct mile : named_scaled_unit, s //https://en.wikipedia.org/wiki/Mile#Nautical_mile struct nautical_mile : named_scaled_unit,si::metre> {}; -#if 0 +//TODO thou //https://en.wikipedia.org/wiki/Thousandth_of_an_inch -struct thou : named_scaled_unit,si::metre> {}; -#endif +//struct thou : named_scaled_unit,si::metre> {}; // different name for thou //https://en.wikipedia.org/wiki/Thousandth_of_an_inch struct mil : named_scaled_unit,si::metre> {}; @@ -89,11 +87,10 @@ constexpr auto operator"" mi(long double l) { return si::length(l); } constexpr auto operator"" naut_mi(long double l) { return si::length(l); } -#if 0 -// thou -constexpr auto operator"" thou(unsigned long long l) { return si::length(l); } -constexpr auto operator"" thou(long double l) { return si::length(l); } -#endif +//TODO thou +//constexpr auto operator"" thou(unsigned long long l) { return si::length(l); } +//constexpr auto operator"" thou(long double l) { return si::length(l); } + // mil constexpr auto operator"" mil(unsigned long long l) { return si::length(l); } constexpr auto operator"" mil(long double l) { return si::length(l); } diff --git a/src/include/units/physical/us/velocity.h b/src/include/units/physical/international/velocity.h similarity index 95% rename from src/include/units/physical/us/velocity.h rename to src/include/units/physical/international/velocity.h index b01d3af9..ca678fd7 100644 --- a/src/include/units/physical/us/velocity.h +++ b/src/include/units/physical/international/velocity.h @@ -25,7 +25,7 @@ #include #include -namespace units::us { +namespace units::international { struct mile_per_hour : deduced_unit {}; @@ -37,4 +37,4 @@ constexpr auto operator"" mph(long double l) { return si::velocity #include -namespace units::us { +namespace units::international { struct cubic_foot : deduced_unit {}; @@ -37,4 +37,4 @@ constexpr auto operator""ft3(long double l) { return si::volume {}; +struct ohm : named_unit {}; struct milliohm : prefixed_unit {}; struct kiloohm : prefixed_unit {}; struct megaohm : prefixed_unit {}; @@ -43,7 +43,7 @@ using resistance = quantity; inline namespace literals { //R -constexpr auto operator""R(unsigned long long l) { return resistance(l); } +constexpr auto operator""_R(unsigned long long l) { return resistance(l); } constexpr auto operator""_R(long double l) { return resistance(l); } //mR diff --git a/src/include/units/physical/us/length.h b/src/include/units/physical/us/length.h index bc4f5782..1abd9f75 100644 --- a/src/include/units/physical/us/length.h +++ b/src/include/units/physical/us/length.h @@ -26,7 +26,6 @@ namespace units::us { -#if 1 //https://en.wikipedia.org/wiki/Foot_(unit)#US_survey_foot //https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors#B6 //struct foot : named_scaled_unit, si::metre> {}; @@ -39,7 +38,7 @@ struct fathom : named_scaled_unit,us::f //https://en.wikipedia.org/wiki/Mile#U.S._survey_mile //https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors#B6 -struct mile : named_scaled_unit,us::foot> {}; +struct mile : named_scaled_unit,us::foot> {}; inline namespace literals { @@ -56,5 +55,5 @@ constexpr auto operator"" mi_us(unsigned long long l) { return si::length(l); } } // namespace literals -#endif + } // namespace units::us diff --git a/test/unit_test/runtime/fmt_units_test.cpp b/test/unit_test/runtime/fmt_units_test.cpp index a1a8f3cd..e46a7a70 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -26,14 +26,26 @@ #include "units/physical/si/velocity.h" #include "units/physical/si/volume.h" #include "units/physical/si/surface_tension.h" -#include "units/physical/us/area.h" -#include "units/physical/us/velocity.h" -#include "units/physical/us/volume.h" +#include "units/physical/us/length.h" +#include "units/physical/imperial/length.h" +#include "units/physical/international/length.h" +#include "units/physical/international/area.h" +#include "units/physical/international/volume.h" +#include "units/physical/international/velocity.h" +#include "units/physical/iau/length.h" +#include "units/physical/typographic/length.h" +#include "units/physical/si/density.h" +#include "units/physical/si/resistance.h" +#include "units/physical/si/voltage.h" #include "units/format.h" #include using namespace units::si; +using namespace units::international; using namespace units::us; +using namespace units::iau; +using namespace units::imperial; +using namespace units::typographic; TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") { @@ -49,6 +61,27 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{}", 1mm) == "1 mm"); CHECK(fmt::format("{}", 1cm) == "1 cm"); CHECK(fmt::format("{}", 1km) == "1 km"); + CHECK(fmt::format("{}", 1ft) == "1 ft"); + CHECK(fmt::format("{}", 1ft_us) == "1 ft(us)"); + CHECK(fmt::format("{}", 1yd) == "1 yd"); + CHECK(fmt::format("{}", 1in) == "1 in"); + CHECK(fmt::format("{}", 1fathom) == "1 fathom"); + CHECK(fmt::format("{}", 1fathom_us) == "1 fathom(us)"); + CHECK(fmt::format("{}", 1mi) == "1 mi"); + CHECK(fmt::format("{}", 1mi_us) == "1 mi(us)"); + CHECK(fmt::format("{}", 1naut_mi) == "1 mi(naut)"); + CHECK(fmt::format("{}", 1ch) == "1 ch"); + CHECK(fmt::format("{}", 1rd) == "1 rd"); + CHECK(fmt::format("{}", 1mil) == "1 mil"); + CHECK(fmt::format("{}", 1pc) == "1 pc"); + CHECK(fmt::format("{}", 1ly) == "1 ly"); + CHECK(fmt::format("{}", 1pc) == "1 pc"); + CHECK(fmt::format("{}", 1angstrom) == "1 angstrom"); + CHECK(fmt::format("{}", 1au) == "1 au"); + CHECK(fmt::format("{}", 1pica_comp) == "1 pica(comp)"); + CHECK(fmt::format("{}", 1pica_prn) == "1 pica(prn)"); + CHECK(fmt::format("{}", 1point_comp) == "1 point(comp)"); + CHECK(fmt::format("{}", 1point_prn) == "1 point(prn)"); } SECTION("mass") @@ -65,6 +98,28 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{}", 1ft2) == "1 ft²"); } + SECTION("density") + { + CHECK(fmt::format("{}", 1kgpm3) == "1 kg/m³"); + } + + SECTION("resistance") + { + CHECK(fmt::format("{}", 1_R) == "1 Ω"); + CHECK(fmt::format("{}", 1kR) == "1 kΩ"); + CHECK(fmt::format("{}", 1mR) == "1 mΩ"); + CHECK(fmt::format("{}", 1MR) == "1 MΩ"); + } + + SECTION("voltage") + { + CHECK(fmt::format("{}", 1V) == "1 V"); + CHECK(fmt::format("{}", 1mV) == "1 mV"); + CHECK(fmt::format("{}", 1uV) == "1 µV"); + CHECK(fmt::format("{}", 1nV) == "1 nV"); + CHECK(fmt::format("{}", 1pV) == "1 pV"); + } + SECTION("volume") { CHECK(fmt::format("{}", 1m3) == "1 m³"); diff --git a/test/unit_test/static/us_test.cpp b/test/unit_test/static/us_test.cpp index 843f0a21..b03a90e3 100644 --- a/test/unit_test/static/us_test.cpp +++ b/test/unit_test/static/us_test.cpp @@ -25,10 +25,10 @@ #include #include #include -#include +#include #include -#include -#include +#include +#include #include namespace {