diff --git a/conanfile.py b/conanfile.py index 4cca3d28..b18a6524 100644 --- a/conanfile.py +++ b/conanfile.py @@ -46,7 +46,7 @@ class UnitsConan(ConanFile): "build_docs": [True, False] } default_options = { - "udls": True, + "udls": False, "downcast_mode": "on", "build_docs": True } diff --git a/docs/usage.rst b/docs/usage.rst index 37e6db6e..b8c1c951 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -128,7 +128,7 @@ udls **Values**: ``True``/``False`` -**Defaulted to**: ``True`` +**Defaulted to**: ``False`` Determines if library should provide User Defined Literals (UDLs) for quantities of various units. @@ -163,7 +163,7 @@ UNITS_UDLS **Values**: ``ON``/``OFF`` -**Defaulted to**: ``ON`` +**Defaulted to**: ``OFF`` Equivalent to `udls`_. diff --git a/example/alternative_namespaces/CMakeLists.txt b/example/alternative_namespaces/CMakeLists.txt index 139c9d94..1095d79f 100644 --- a/example/alternative_namespaces/CMakeLists.txt +++ b/example/alternative_namespaces/CMakeLists.txt @@ -25,6 +25,7 @@ cmake_minimum_required(VERSION 3.2) function(add_example target) add_executable(${target}_alt ${target}.cpp) target_link_libraries(${target}_alt PRIVATE mp-units::mp-units) + target_compile_definitions(${target}_alt PRIVATE UNITS_UDLS=1) endfunction() add_example(box_example mp-units::si) diff --git a/example/avg_speed.cpp b/example/avg_speed.cpp index e00d90d7..4b03a180 100644 --- a/example/avg_speed.cpp +++ b/example/avg_speed.cpp @@ -73,8 +73,8 @@ void example() { // SI (int) { - using namespace units::isq::si::literals; - constexpr Length auto distance = 220_q_km; // constructed from a UDL + 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 std::cout << "SI units with 'int' as representation\n"; @@ -87,8 +87,8 @@ void example() // SI (double) { - using namespace units::isq::si::literals; - constexpr Length auto distance = 220._q_km; // constructed from a UDL + 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 std::cout << "\nSI units with 'double' as representation\n"; @@ -103,8 +103,8 @@ void example() // Customary Units (int) { - using namespace units::isq::si::international::literals; - constexpr Length auto distance = 140_q_mi; // constructed from a UDL + 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 std::cout << "\nUS Customary Units with 'int' as representation\n"; @@ -119,8 +119,8 @@ void example() // Customary Units (double) { - using namespace units::isq::si::international::literals; - constexpr Length auto distance = 140._q_mi; // constructed from a UDL + 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 std::cout << "\nUS Customary Units with 'double' as representation\n"; @@ -137,8 +137,8 @@ void example() // CGS (int) { - using namespace units::isq::si::cgs::literals; - constexpr Length auto distance = 22'000'000_q_cm; // constructed from a UDL + 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 std::cout << "\nCGS units with 'int' as representation\n"; @@ -156,8 +156,8 @@ void example() // CGS (double) { - using namespace units::isq::si::cgs::literals; - constexpr Length auto distance = 22'000'000._q_cm; // constructed from a UDL + 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 std::cout << "\nCGS units with 'double' as representation\n"; diff --git a/example/box_example.cpp b/example/box_example.cpp index 0e7afbaf..92743e3e 100644 --- a/example/box_example.cpp +++ b/example/box_example.cpp @@ -39,43 +39,37 @@ namespace { using namespace units::isq; +using namespace si::references; -using m = si::metre; -using m2 = si::square_metre; -using m3 = si::cubic_metre; -using kg = si::kilogram; -using N = si::newton; -using kgpm3 = si::kilogram_per_metre_cub; - -inline constexpr auto g = si::si2019::standard_gravity<>; -inline constexpr si::density air_density(1.225); +inline constexpr Acceleration auto g = si::si2019::standard_gravity<>; +inline constexpr Density auto air_density = 1.225 * (kg / m3); class Box { - si::area base_; - si::length height_; - si::density density_ = air_density; + si::area base_; + si::length height_; + si::density density_ = air_density; public: - constexpr Box(const si::length& length, const si::length& width, si::length height) : base_(length * width), height_(std::move(height)) {} + constexpr Box(const si::length& length, const si::length& width, si::length height) : base_(length * width), height_(std::move(height)) {} - [[nodiscard]] constexpr si::force filled_weight() const + [[nodiscard]] constexpr si::force filled_weight() const { - const si::volume volume = base_ * height_; - const si::mass mass = density_ * volume; + const Volume auto volume = base_ * height_; + const Mass auto mass = density_ * volume; return mass * g; } - [[nodiscard]] constexpr si::length fill_level(const si::mass& measured_mass) const + [[nodiscard]] constexpr si::length fill_level(const si::mass& measured_mass) const { return height_ * measured_mass * g / filled_weight(); } - [[nodiscard]] constexpr si::volume spare_capacity(const si::mass& measured_mass) const + [[nodiscard]] constexpr si::volume spare_capacity(const si::mass& measured_mass) const { return (height_ - fill_level(measured_mass)) * base_; } - constexpr void set_contents_density(const si::density& density_in) + constexpr void set_contents_density(const si::density& density_in) { assert(density_in > air_density); density_ = density_in; @@ -88,14 +82,13 @@ public: int main() { using namespace units; - using namespace si::literals; - const si::length height(200.0_q_mm); - auto box = Box(1000.0_q_mm, 500.0_q_mm, height); - box.set_contents_density(1000.0_q_kg_per_m3); + const si::length height = 200.0 * mm; + auto box = Box(1000.0 * mm, 500.0 * mm, height); + box.set_contents_density(1000.0 * (kg / m3)); - 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 + const auto fill_time = 200.0 * s; // time since starting fill + const auto measured_mass = 20.0 * kg; // measured mass at fill_time const Length auto fill_level = box.fill_level(measured_mass); const Dimensionless auto fill_percent = quantity_cast(fill_level / height); diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp index e1300e91..5d41e054 100644 --- a/example/capacitor_time_curve.cpp +++ b/example/capacitor_time_curve.cpp @@ -34,27 +34,28 @@ int main() { using namespace units::isq; using namespace units::isq::si; + using namespace units::isq::si::references; std::cout << "mp-units capacitor time curve example...\n"; std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield); std::cout.precision(3); - constexpr auto C = 0.47_q_uF; - constexpr auto V0 = 5.0_q_V; - constexpr auto R = 4.7_q_kR; + constexpr auto C = 0.47 * uF; + constexpr auto V0 = 5.0 * V; + constexpr auto R = 4.7 * kR; - for (auto t = 0_q_ms; t <= 50_q_ms; ++t) { + for (auto t = 0 * ms; t <= 50 * ms; ++t) { const Voltage auto Vt = V0 * units::exp(-t / (R * C)); std::cout << "at " << t << " voltage is "; - if (Vt >= 1_q_V) + if (Vt >= 1 * V) std::cout << Vt; - else if (Vt >= 1_q_mV) + else if (Vt >= 1 * mV) std::cout << quantity_cast(Vt); - else if (Vt >= 1_q_uV) + else if (Vt >= 1 * uV) std::cout << quantity_cast(Vt); - else if (Vt >= 1_q_nV) + else if (Vt >= 1 * nV) std::cout << quantity_cast(Vt); else std::cout << quantity_cast(Vt); diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index 6a130b2f..2d3516d3 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -29,55 +29,54 @@ namespace { -using namespace units; - void simple_quantities() { - using namespace units::isq::si; - using namespace units::isq::si::international; + using namespace units::isq; + using namespace units::isq::si::references; + using namespace units::isq::si::international::references; - using distance = length; - using duration = isq::si::time; + using distance = si::length; + using duration = si::time; - constexpr distance km = 1.0_q_km; - constexpr distance miles = 1.0_q_mi; + constexpr distance kilometers = 1.0 * km; + constexpr distance miles = 1.0 * mi; - constexpr duration sec = 1_q_s; - constexpr duration min = 1_q_min; - constexpr duration hr = 1_q_h; + constexpr duration seconds = 1 * s; + constexpr duration minutes = 1 * min; + constexpr duration hours = 1 * 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"; - std::cout << km << '\n'; + std::cout << kilometers << '\n'; std::cout << miles << '\n'; - std::cout << sec << '\n'; - std::cout << min << '\n'; - std::cout << hr << "\n\n"; + std::cout << seconds << '\n'; + std::cout << minutes << '\n'; + std::cout << hours << "\n\n"; } void quantities_with_typed_units() { using namespace units::isq; - using namespace units::isq::si; - using namespace units::isq::si::international; + using namespace units::isq::si::references; + using namespace units::isq::si::international::references; - constexpr length km = 1.0_q_km; - constexpr length miles = 1.0_q_mi; + constexpr si::length kilometers = 1.0 * km; + constexpr si::length miles = 1.0 * mi; std::cout.precision(6); - constexpr si::time sec = 1_q_s; - constexpr si::time min = 1_q_min; - constexpr si::time hr = 1_q_h; + constexpr si::time seconds = 1 * s; + constexpr si::time minutes = 1 * min; + constexpr si::time hours = 1 * h; std::cout << "A more flexible option is to provide separate types for each unit,\n\n"; - std::cout << km << '\n'; + std::cout << kilometers << '\n'; std::cout << miles << '\n'; - std::cout << sec << '\n'; - std::cout << min << '\n'; - std::cout << hr << "\n\n"; + std::cout << seconds << '\n'; + std::cout << minutes << '\n'; + std::cout << hours << "\n\n"; - constexpr length meter = 1_q_m; + constexpr si::length 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"; @@ -105,34 +104,35 @@ void quantities_with_typed_units() void calcs_comparison() { - using namespace units::isq::si; + using namespace units::isq; + using namespace units::isq::si::references; std::cout << "\nA distinct unit for each type is efficient and accurate\n" "when adding two values of the same very big\n" "or very small type:\n\n"; - length L1A = 2._q_fm; - length L2A = 3._q_fm; - length LrA = L1A + L2A; + si::length L1A = 2. * fm; + si::length L2A = 3. * fm; + si::length 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"; - length L1B = L1A; - length L2B = L2A; - length LrB = L1B + L2B; + si::length L1B = L1A; + si::length L2B = L2A; + si::length 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"; - area ArA = L1A * L2A; + si::area 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"; - area ArB = L1B * L2B; + si::area ArB = L1B * L2B; fmt::print("{:%.30Q %q}\n * {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1B, L2B, ArB); } diff --git a/example/conversion_factor.cpp b/example/conversion_factor.cpp index 7e370522..436242ec 100644 --- a/example/conversion_factor.cpp +++ b/example/conversion_factor.cpp @@ -43,10 +43,11 @@ inline constexpr std::common_type_t int main() { using namespace units::isq::si; + using namespace units::isq::si::references; std::cout << "conversion factor in mp-units...\n\n"; - constexpr length lengthA = 2.0_q_m; + constexpr length lengthA = 2.0 * m; constexpr length lengthB = lengthA; std::cout << fmt::format("lengthA( {} ) and lengthB( {} )\n", lengthA, lengthB) diff --git a/example/foot_pound_second.cpp b/example/foot_pound_second.cpp index 841068f7..0fafd1dc 100644 --- a/example/foot_pound_second.cpp +++ b/example/foot_pound_second.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -62,8 +63,8 @@ auto fmt_line(const Q 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; + 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)) @@ -79,17 +80,18 @@ void print_details(std::string_view description, const Ship& ship) int main() { - using namespace units::isq::si::literals; - using namespace units::isq::si::fps::literals; + using namespace units::isq::si::references; + using namespace units::isq::si::fps::references; + using units::isq::si::fps::references::ft; // collides with si::femtotonne (alias unit of mass) // 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}}; + auto bismark = Ship{.length{251. * m}, .draft{9.3 * m}, .beam{36 * m}, .speed{56 * (km / h)}, .mass{50'300 * t}, .mainGuns{380 * mm}, .shellMass{800 * kg}, .shellSpeed{820. * (m / s)}, .power{110.45 * 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}}; + auto iowa = Ship{.length{860. * ft}, .draft{37. * ft + 2. * in}, .beam{108. * ft + 2. * in}, .speed{33 * knot}, .mass{57'540 * lton}, .mainGuns{16 * in}, .shellMass{2700 * lb}, .shellSpeed{2690. * (ft / s)}, .power{212'000 * 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}}; + auto kgv = Ship{.length{745.1 * ft}, .draft{33. * ft + 7.5 * in}, .beam{103.2 * ft + 2.5 * in}, .speed{28.3 * knot}, .mass{42'245 * lton}, .mainGuns{14 * in}, .shellMass{1'590 * lb}, .shellSpeed{2483. * (ft / s)}, .power{110'000 * hp}}; print_details("KMS Bismark, defined in appropriate units from the SI system", bismark); std::cout << "\n\n"; diff --git a/example/hello_units.cpp b/example/hello_units.cpp index b7513dbd..6208cec2 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -20,6 +20,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#define UNITS_UDLS 1 + #include #include #include // IWYU pragma: keep diff --git a/example/kalman_filter-alpha_beta_filter_example2.cpp b/example/kalman_filter-alpha_beta_filter_example2.cpp index 52f53ead..68f0fdf0 100644 --- a/example/kalman_filter-alpha_beta_filter_example2.cpp +++ b/example/kalman_filter-alpha_beta_filter_example2.cpp @@ -41,9 +41,9 @@ struct state_variable { }; using namespace units::isq; -using namespace units::isq::si::literals; +using namespace units::isq::si::references; -constexpr auto radar_transmit_interval = 5.0_q_s; +constexpr auto radar_transmit_interval = 5.0 * s; constexpr double kalman_range_gain = 0.2; constexpr double kalman_speed_gain = 0.1; @@ -74,16 +74,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.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 measurements = std::array{0.0 * m, // N.B measurement[0] is unknown and unused + 30110.0 * m, 30265.0 * m, 30740.0 * m, 30750.0 * m, 31135.0 * m, + 31015.0 * m, 31180.0 * m, 31610.0 * m, 31960.0 * m, 31865.0 * m}; constexpr auto num_measurements = measurements.size(); std::array 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'000_q_m; - track[0].speed.estimated_current_state = 40.0_q_m_per_s; + track[0].range.estimated_current_state = 30'000 * m; + track[0].speed.estimated_current_state = 40.0 * (m / s); for (auto n = 0U; n < num_measurements; ++n) { if (n > 0) { diff --git a/example/linear_algebra.cpp b/example/linear_algebra.cpp index e98b69bd..1dbd658c 100644 --- a/example/linear_algebra.cpp +++ b/example/linear_algebra.cpp @@ -60,7 +60,7 @@ std::ostream& operator<<(std::ostream& os, const matrix& v) namespace { using namespace units::isq; -using namespace units::isq::si::literals; +using namespace units::isq::si::references; template using vector = std::math::fs_vector; @@ -73,9 +73,9 @@ void vector_of_quantity_add() { std::cout << "\nvector_of_quantity_add:\n"; - vector> v = { 1_q_m, 2_q_m, 3_q_m }; - vector> u = { 3_q_m, 2_q_m, 1_q_m }; - vector> t = { 3_q_km, 2_q_km, 1_q_km }; + vector> v = { 1 * m, 2 * m, 3 * m }; + vector> u = { 3 * m, 2 * m, 1 * m }; + vector> t = { 3 * km, 2 * km, 1 * km }; std::cout << "v = " << v << "\n"; std::cout << "u = " << u << "\n"; @@ -90,28 +90,28 @@ void vector_of_quantity_multiply_same() { std::cout << "\nvector_of_quantity_multiply_same:\n"; - vector> v = { 1_q_m, 2_q_m, 3_q_m }; - vector> u = { 3_q_m, 2_q_m, 1_q_m }; + vector> v = { 1 * m, 2 * m, 3 * m }; + vector> u = { 3 * m, 2 * m, 1 * m }; std::cout << "v = " << v << "\n"; std::cout << "u = " << u << "\n"; std::cout << "v * u = " << v * u << "\n"; - std::cout << "2_q_m * v = " << 2._q_m * v << "\n"; + std::cout << "2 * m * v = " << 2. * m * v << "\n"; } void vector_of_quantity_multiply_different() { std::cout << "\nvector_of_quantity_multiply_different:\n"; - vector> v = { 1_q_N, 2_q_N, 3_q_N }; - vector> u = { 3_q_m, 2_q_m, 1_q_m }; + vector> v = { 1 * N, 2 * N, 3 * N }; + vector> u = { 3 * m, 2 * m, 1 * m }; std::cout << "v = " << v << "\n"; std::cout << "u = " << u << "\n"; std::cout << "v * u = " << v * u << "\n"; - std::cout << "2_q_N * u = " << 2._q_N * u << "\n"; + std::cout << "2 * N * u = " << 2. * N * u << "\n"; std::cout << "2 * u = " << 2 * u << "\n"; } @@ -119,12 +119,12 @@ void vector_of_quantity_divide_by_scalar() { std::cout << "\nvector_of_quantity_divide_by_scalar:\n"; - vector> v = { 4_q_m, 8_q_m, 12_q_m }; + vector> v = { 4 * m, 8 * m, 12 * m }; std::cout << "v = " << v << "\n"; // TODO Uncomment when bug in the LA is fixed - // std::cout << "v / 2_q_s = " << v / 2_q_s << "\n"; + // std::cout << "v / (2 * s) = " << v / (2 * s) << "\n"; // std::cout << "v / 2 = " << v / 2 << "\n"; } @@ -140,9 +140,9 @@ void matrix_of_quantity_add() { std::cout << "\nmatrix_of_quantity_add:\n"; - matrix> 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> 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> 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 }}; + matrix> v = {{ 1 * m, 2 * m, 3 * m }, { 4 * m, 5 * m, 6 * m }, { 7 * m, 8 * m, 9 * m }}; + matrix> u = {{ 3 * m, 2 * m, 1 * m }, { 3 * m, 2 * m, 1 * m }, { 3 * m, 2 * m, 1 * m }}; + matrix> t = {{ 3 * mm, 2 * mm, 1 * mm }, { 3 * mm, 2 * mm, 1 * mm }, { 3 * mm, 2 * mm, 1 * mm }}; std::cout << "v =\n" << v << "\n"; std::cout << "u =\n" << u << "\n"; @@ -159,28 +159,28 @@ void matrix_of_quantity_multiply_same() { std::cout << "\nmatrix_of_quantity_multiply_same:\n"; - matrix> 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> u = { 3_q_m, 2_q_m, 1_q_m }; + matrix> v = {{ 1 * m, 2 * m, 3 * m }, { 4 * m, 5 * m, 6 * m }, { 7 * m, 8 * m, 9 * m }}; + vector> u = { 3 * m, 2 * m, 1 * m }; std::cout << "v =\n" << v << "\n"; std::cout << "u =\n" << u << "\n"; std::cout << "v * u =\n" << v * u << "\n"; - std::cout << "2_q_m * u =\n" << 2._q_m * u << "\n"; + std::cout << "2 * m * u =\n" << 2. * m * u << "\n"; } void matrix_of_quantity_multiply_different() { std::cout << "\nmatrix_of_quantity_multiply_different:\n"; - vector> v = { 1_q_N, 2_q_N, 3_q_N }; - matrix> 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 }}; + vector> v = { 1 * N, 2 * N, 3 * N }; + matrix> u = {{ 1 * m, 2 * m, 3 * m }, { 4 * m, 5 * m, 6 * m }, { 7 * m, 8 * m, 9 * m }}; std::cout << "v =\n" << v << "\n"; std::cout << "u =\n" << u << "\n"; std::cout << "v * u =\n" << v * u << "\n"; - std::cout << "2_q_N * u =\n" << 2._q_N * u << "\n"; + std::cout << "2 * N * u =\n" << 2. * N * u << "\n"; std::cout << "2 * u =\n" << 2 * u << "\n"; } @@ -188,12 +188,12 @@ void matrix_of_quantity_divide_by_scalar() { std::cout << "\nmatrix_of_quantity_divide_by_scalar:\n"; - matrix> 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 }}; + matrix> v = {{ 2 * m, 4 * m, 6 * m }, { 4 * m, 6 * m, 8 * m }, { 8 * m, 4 * m, 2 * m }}; std::cout << "v =\n" << v << "\n"; // TODO Uncomment when bug in the LA is fixed - // std::cout << "v / 2_q_s =\n" << v / 2_q_s << "\n"; + // std::cout << "v / (2 * s) =\n" << v / (2 * s) << "\n"; // std::cout << "v / 2 =\n" << v / 2 << "\n"; } @@ -239,7 +239,7 @@ void quantity_of_vector_multiply_same() std::cout << "u = " << u << "\n"; std::cout << "v * u = " << v * u << "\n"; - std::cout << "2_q_m * v = " << 2._q_m * v << "\n"; + std::cout << "2 * m * v = " << 2. * m * v << "\n"; } void quantity_of_vector_multiply_different() @@ -253,7 +253,7 @@ void quantity_of_vector_multiply_different() std::cout << "u = " << u << "\n"; std::cout << "v * u = " << v * u << "\n"; - std::cout << "2_q_N * u = " << 2._q_N * u << "\n"; + std::cout << "2 * N * u = " << 2. * N * u << "\n"; std::cout << "2 * u = " << 2 * u << "\n"; } @@ -266,7 +266,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 / 2_q_s = " << v / 2_q_s << "\n"; + // std::cout << "v / 2 * s = " << v / 2 * s << "\n"; // std::cout << "v / 2 = " << v / 2 << "\n"; } @@ -311,7 +311,7 @@ void quantity_of_matrix_multiply_same() std::cout << "u =\n" << u << "\n"; std::cout << "v * u =\n" << v * u << "\n"; - std::cout << "2_q_m * u =\n" << 2._q_m * u << "\n"; + std::cout << "2 * m * u =\n" << 2. * m * u << "\n"; } void quantity_of_matrix_multiply_different() @@ -325,7 +325,7 @@ void quantity_of_matrix_multiply_different() std::cout << "u =\n" << u << "\n"; std::cout << "v * u =\n" << v * u << "\n"; - std::cout << "2_q_N * u =\n" << 2._q_N * u << "\n"; + std::cout << "2 * N * u =\n" << 2. * N * u << "\n"; std::cout << "2 * u =\n" << 2 * u << "\n"; } @@ -338,7 +338,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 / 2_q_s =\n" << v / 2_q_s << "\n"; + // std::cout << "v / (2 * s) =\n" << v / (2 * s) << "\n"; // std::cout << "v / 2 =\n" << v / 2 << "\n"; } diff --git a/example/total_energy.cpp b/example/total_energy.cpp index 7420f241..0398c82f 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -43,14 +43,14 @@ Energy auto total_energy(Momentum auto p, Mass auto m, Speed auto c) void si_example() { using namespace units::isq::si; - using GeV = gigaelectronvolt; + using namespace units::isq::si::references; constexpr Speed auto c = si2019::speed_of_light<>; 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. * GeV / c; + const Mass auto m = 3. * GeV / pow<2>(c); const Energy auto E = total_energy(p, m, c); std::cout << "[in GeV]\n" @@ -68,17 +68,16 @@ void si_example() << "E = " << E_si << "\n"; std::cout << "\n[converted from SI units back to GeV]\n" - << "E = " << quantity_cast(E_si) << "\n"; + << "E = " << quantity_cast(E_si) << "\n"; } void natural_example() { using namespace units::isq::natural; - using GeV = gigaelectronvolt; constexpr Speed auto c = speed_of_light<>; - const momentum p(4); - const mass m(3); + const momentum p(4); + const mass m(3); const Energy auto E = total_energy(p, m, c); std::cout << "\n*** Natural units (c = " << c << ") ***\n" diff --git a/example/unknown_dimension.cpp b/example/unknown_dimension.cpp index aed204d8..8e5fe29a 100644 --- a/example/unknown_dimension.cpp +++ b/example/unknown_dimension.cpp @@ -38,15 +38,15 @@ constexpr units::isq::Speed auto avg_speed(D d, T t) void example() { using namespace units::isq; - using namespace units::isq::si::literals; + using namespace units::isq::si::references; - Length auto d1 = 123_q_m; - Time auto t1 = 10_q_s; + Length auto d1 = 123 * m; + Time auto t1 = 10 * s; Speed auto v1 = avg_speed(d1, t1); - 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; + auto temp1 = v1 * (50 * m); // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit' + Speed auto v2 = temp1 / (100 * m); // back to known dimensions again + Length auto d2 = v2 * (60 * s); std::cout << "d1 = " << d1 << '\n'; std::cout << "t1 = " << t1 << '\n'; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e6f79c03..2707c44d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,7 +27,7 @@ project(mp-units ) option(UNITS_AS_SYSTEM_HEADERS "Exports library as system headers" OFF) -option(UNITS_UDLS "Enables definitions of User Defined Literals (UDLs) provided for quantities of various units" ON) +option(UNITS_UDLS "Enables definitions of User Defined Literals (UDLs) provided for quantities of various units" OFF) message(STATUS "UNITS_AS_SYSTEM_HEADERS: ${UNITS_AS_SYSTEM_HEADERS}") message(STATUS "UNITS_UDLS: ${UNITS_UDLS}") diff --git a/test/unit_test/runtime/CMakeLists.txt b/test/unit_test/runtime/CMakeLists.txt index 08bace2f..e70c8cc3 100644 --- a/test/unit_test/runtime/CMakeLists.txt +++ b/test/unit_test/runtime/CMakeLists.txt @@ -35,6 +35,7 @@ target_link_libraries(unit_tests_runtime PRIVATE mp-units::mp-units Catch2::Catch2 ) +target_compile_definitions(unit_tests_runtime PRIVATE UNITS_UDLS=1) if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options(unit_tests_runtime PRIVATE diff --git a/test/unit_test/static/CMakeLists.txt b/test/unit_test/static/CMakeLists.txt index f3981ce4..95ed6048 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -37,6 +37,7 @@ target_link_libraries(unit_tests_static_truncating PRIVATE target_compile_options(unit_tests_static_truncating PRIVATE $,/wd4242 /wd4244,-Wno-conversion> ) +target_compile_definitions(unit_tests_static_truncating PRIVATE UNITS_UDLS=1) add_library(unit_tests_static cgs_test.cpp @@ -73,3 +74,4 @@ target_link_libraries(unit_tests_static PRIVATE unit_tests_static_truncating mp-units::mp-units ) +target_compile_definitions(unit_tests_static PRIVATE UNITS_UDLS=1)