From 72e03f4f5969bd3b2b6b507df3079b86078cecf6 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:23:30 +0200 Subject: [PATCH 01/44] [msvc][fix] msvc needs explicit namespace for some using-declarations --- test/static/dimension_test.cpp | 2 +- test/static/quantity_spec_test.cpp | 4 ++-- test/static/reference_test.cpp | 4 ++-- test/static/unit_test.cpp | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/static/dimension_test.cpp b/test/static/dimension_test.cpp index 8064831e..f1d64590 100644 --- a/test/static/dimension_test.cpp +++ b/test/static/dimension_test.cpp @@ -33,7 +33,7 @@ namespace { using namespace mp_units; -using dimension_one_ = struct dimension_one; +using dimension_one_ = struct mp_units::dimension_one; // clang-format off inline constexpr struct length_ final : base_dimension<"L"> {} length; diff --git a/test/static/quantity_spec_test.cpp b/test/static/quantity_spec_test.cpp index ee4e86a8..ed4cb359 100644 --- a/test/static/quantity_spec_test.cpp +++ b/test/static/quantity_spec_test.cpp @@ -33,8 +33,8 @@ namespace { using namespace mp_units; -using dimensionless_ = struct dimensionless; -using dim_one_ = struct dimension_one; +using dimensionless_ = struct mp_units::dimensionless; +using dim_one_ = struct mp_units::dimension_one; // clang-format off inline constexpr struct dim_length_ final : base_dimension<"L"> {} dim_length; diff --git a/test/static/reference_test.cpp b/test/static/reference_test.cpp index 65abe0bb..f7f3d709 100644 --- a/test/static/reference_test.cpp +++ b/test/static/reference_test.cpp @@ -34,8 +34,8 @@ namespace { using namespace mp_units; -using dimensionless_ = struct dimensionless; -using one_ = struct one; +using dimensionless_ = struct mp_units::dimensionless; +using one_ = struct mp_units::one; // base dimensions // clang-format off diff --git a/test/static/unit_test.cpp b/test/static/unit_test.cpp index ba7ecb4c..c16ea66a 100644 --- a/test/static/unit_test.cpp +++ b/test/static/unit_test.cpp @@ -35,8 +35,8 @@ namespace { using namespace mp_units; using namespace mp_units::detail; -using one_ = struct one; -using percent_ = struct percent; +using one_ = struct mp_units::one; +using percent_ = struct mp_units::percent; // base dimensions // clang-format off From 33837c5042720300b05f2d50299f117f80fa34b5 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:43:57 +0200 Subject: [PATCH 02/44] [msvc][fix] some short names hide global identifier --- example/glide_computer.cpp | 10 ++++----- .../mp-units/framework/dimension_concepts.h | 2 +- .../framework/quantity_point_concepts.h | 6 ++--- .../mp-units/framework/quantity_spec.h | 22 +++++++++---------- .../framework/quantity_spec_concepts.h | 2 +- .../include/mp-units/framework/symbol_text.h | 4 ++-- src/core/include/mp-units/framework/unit.h | 8 +++---- test/static/quantity_test.cpp | 4 ++-- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/example/glide_computer.cpp b/example/glide_computer.cpp index 133a7713..f06062fe 100644 --- a/example/glide_computer.cpp +++ b/example/glide_computer.cpp @@ -169,7 +169,7 @@ void example() const auto gliders = get_gliders(); const auto waypoints = get_waypoints(); const auto weather_conditions = get_weather_conditions(); - const task t = {waypoints[0], waypoints[1], waypoints[0]}; + const task glider_task = {waypoints[0], waypoints[1], waypoints[0]}; const aircraft_tow tow = {400 * m, 1.6 * m / s}; const timestamp start_time(std::chrono::system_clock::now()); @@ -177,16 +177,16 @@ void example() print(gliders); print(waypoints); print(weather_conditions); - print(t); + print(glider_task); print(tow); - for (const auto& g : gliders) { + for (const auto& glider : gliders) { for (const auto& c : weather_conditions) { - const std::string txt = "Scenario: Glider = " + g.name + ", Weather = " + c.first; + const std::string txt = "Scenario: Glider = " + glider.name + ", Weather = " + c.first; std::cout << txt << "\n"; std::cout << MP_UNITS_STD_FMT::format("{0:=^{1}}\n\n", "", txt.size()); - estimate(start_time, g, c.second, t, sfty, tow); + estimate(start_time, glider, c.second, glider_task, sfty, tow); std::cout << "\n\n"; } diff --git a/src/core/include/mp-units/framework/dimension_concepts.h b/src/core/include/mp-units/framework/dimension_concepts.h index 7517ea7f..b5225399 100644 --- a/src/core/include/mp-units/framework/dimension_concepts.h +++ b/src/core/include/mp-units/framework/dimension_concepts.h @@ -54,7 +54,7 @@ void to_base_specialization_of_base_dimension(const volatile base_dimension inline constexpr bool is_derived_from_specialization_of_base_dimension = - requires(T* t) { to_base_specialization_of_base_dimension(t); }; + requires(T* type) { to_base_specialization_of_base_dimension(type); }; /** * @brief A concept matching all named base dimensions in the library. diff --git a/src/core/include/mp-units/framework/quantity_point_concepts.h b/src/core/include/mp-units/framework/quantity_point_concepts.h index a262ea7d..bd8cb5b2 100644 --- a/src/core/include/mp-units/framework/quantity_point_concepts.h +++ b/src/core/include/mp-units/framework/quantity_point_concepts.h @@ -45,7 +45,7 @@ void to_base_specialization_of_absolute_point_origin(const volatile absolute_poi template inline constexpr bool is_derived_from_specialization_of_absolute_point_origin = - requires(T* t) { to_base_specialization_of_absolute_point_origin(t); }; + requires(T* type) { to_base_specialization_of_absolute_point_origin(type); }; } // namespace detail @@ -67,7 +67,7 @@ void to_base_specialization_of_relative_point_origin(const volatile relative_poi template inline constexpr bool is_derived_from_specialization_of_relative_point_origin = - requires(T* t) { to_base_specialization_of_relative_point_origin(t); }; + requires(T* type) { to_base_specialization_of_relative_point_origin(type); }; struct point_origin_interface; @@ -100,7 +100,7 @@ void to_base_specialization_of_quantity_point(const volatile quantity_point inline constexpr bool is_derived_from_specialization_of_quantity_point = - requires(T* t) { to_base_specialization_of_quantity_point(t); }; + requires(T* type) { to_base_specialization_of_quantity_point(type); }; template requires is_derived_from_specialization_of_quantity_point diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 88eec204..94bce96a 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -765,14 +765,14 @@ template, type_list) { constexpr auto n = get_complexity(Num{}); - constexpr auto d = get_complexity(Den{}); - constexpr auto max_compl = n > d ? n : d; + constexpr auto den = get_complexity(Den{}); + constexpr auto max_compl = n > den ? n : den; - if constexpr (max_compl == Complexity || ((n >= d && !requires { explode_to_equation(Num{}); }) || - (n < d && !requires { explode_to_equation(Den{}); }))) + if constexpr (max_compl == Complexity || ((n >= den && !requires { explode_to_equation(Num{}); }) || + (n < den && !requires { explode_to_equation(Den{}); }))) return explode_result{(map_power(Num{}) * ... * map_power(Nums{})) / (map_power(Den{}) * ... * map_power(Dens{}))}; else { - if constexpr (n >= d) { + if constexpr (n >= den) { constexpr auto res = explode_to_equation(Num{}); return explode((res.equation * ... * map_power(Nums{})) / (map_power(Den{}) * ... * map_power(Dens{}))) @@ -801,8 +801,8 @@ template template [[nodiscard]] consteval auto explode(Q, type_list<>, type_list) { - constexpr auto d = get_complexity(Den{}); - if constexpr (d == Complexity || !requires { explode_to_equation(Den{}); }) + constexpr auto den = get_complexity(Den{}); + if constexpr (den == Complexity || !requires { explode_to_equation(Den{}); }) return explode_result{dimensionless / (map_power(Den{}) * ... * map_power(Dens{}))}; else { constexpr auto res = explode_to_equation(Den{}); @@ -820,8 +820,8 @@ template template [[nodiscard]] consteval auto explode(Q q) { - constexpr auto c = get_complexity(Q{}); - if constexpr (c > Complexity) + constexpr auto complexity = get_complexity(Q{}); + if constexpr (complexity > Complexity) return explode(q, type_list_sort{}, type_list_sort{}); else @@ -831,8 +831,8 @@ template template [[nodiscard]] consteval auto explode(Q q) { - constexpr auto c = get_complexity(Q{}); - if constexpr (c > Complexity && requires { Q::_equation_; }) { + constexpr auto complexity = get_complexity(Q{}); + if constexpr (complexity > Complexity && requires { Q::_equation_; }) { constexpr auto res = explode_to_equation(Q{}); return explode(res.equation).common_convertibility_with(res); } else diff --git a/src/core/include/mp-units/framework/quantity_spec_concepts.h b/src/core/include/mp-units/framework/quantity_spec_concepts.h index 9eac9f2d..054742f0 100644 --- a/src/core/include/mp-units/framework/quantity_spec_concepts.h +++ b/src/core/include/mp-units/framework/quantity_spec_concepts.h @@ -71,7 +71,7 @@ void to_base_specialization_of_quantity_spec(const volatile quantity_spec inline constexpr bool is_derived_from_specialization_of_quantity_spec = - requires(T* t) { to_base_specialization_of_quantity_spec(t); }; + requires(T* type) { to_base_specialization_of_quantity_spec(type); }; /** * @brief Concept matching all named quantity specification types diff --git a/src/core/include/mp-units/framework/symbol_text.h b/src/core/include/mp-units/framework/symbol_text.h index f0a75313..d2875821 100644 --- a/src/core/include/mp-units/framework/symbol_text.h +++ b/src/core/include/mp-units/framework/symbol_text.h @@ -128,9 +128,9 @@ public: MP_UNITS_EXPECTS(detail::is_basic_literal_character_set(a)); } - constexpr symbol_text(const fixed_u8string& u, const fixed_string& a) : unicode_(u), ascii_(a) + constexpr symbol_text(const fixed_u8string& u, const fixed_string& text) : unicode_(u), ascii_(text) { - MP_UNITS_EXPECTS(detail::is_basic_literal_character_set(a.data_)); + MP_UNITS_EXPECTS(detail::is_basic_literal_character_set(text.data_)); } [[nodiscard]] constexpr const auto& unicode() const { return unicode_; } diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index 411f3256..f6a52e4f 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -520,9 +520,9 @@ template template [[nodiscard]] consteval auto get_canonical_unit_impl(const type_list&) { - auto m = (mp_units::mag<1> * ... * get_canonical_unit_impl(Us{}, Us{}).mag); + auto magnitude = (mp_units::mag<1> * ... * get_canonical_unit_impl(Us{}, Us{}).mag); auto u = (one * ... * get_canonical_unit_impl(Us{}, Us{}).reference_unit); - return canonical_unit{m, u}; + return canonical_unit{magnitude, u}; } template @@ -654,8 +654,8 @@ template else if constexpr (is_integral(canonical_rhs.mag / canonical_lhs.mag)) return u1; else { - constexpr auto cm = detail::common_magnitude(canonical_lhs.mag, canonical_rhs.mag); - return scaled_unit{}; + constexpr auto common_magnitude = detail::common_magnitude(canonical_lhs.mag, canonical_rhs.mag); + return scaled_unit{}; } } } diff --git a/test/static/quantity_test.cpp b/test/static/quantity_test.cpp index d8ddfe60..7fcabec2 100644 --- a/test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -311,9 +311,9 @@ struct derived_quantity : quantity { R::operator=(t); return *this; } - constexpr derived_quantity& operator=(R&& t) + constexpr derived_quantity& operator=(R&& other) { - R::operator=(std::move(t)); + R::operator=(std::move(other)); return *this; } // NOLINTBEGIN(google-explicit-constructor, hicpp-explicit-conversions) From aa26488b60cc485caef0f26f8e7127be1b26725d Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:47:11 +0200 Subject: [PATCH 03/44] [msvc][fix] msvc compiler has different behaviour for *= and * at compile time (issue reported) --- src/core/include/mp-units/framework/quantity.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index 9933a760..d957cb14 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -448,7 +448,7 @@ public: } friend constexpr decltype(auto) operator*=(Q&& lhs, const Value& v) { - lhs.numerical_value_is_an_implementation_detail_ *= v; + lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ * v; return std::forward(lhs); } @@ -461,7 +461,8 @@ public: } friend constexpr decltype(auto) operator*=(Q1&& lhs, const Q2& rhs) { - lhs.numerical_value_is_an_implementation_detail_ *= rhs.numerical_value_is_an_implementation_detail_; + lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ * + rhs.numerical_value_is_an_implementation_detail_; return std::forward(lhs); } @@ -475,7 +476,7 @@ public: friend constexpr decltype(auto) operator/=(Q&& lhs, const Value& v) { MP_UNITS_EXPECTS_DEBUG(v != quantity_values::zero()); - lhs.numerical_value_is_an_implementation_detail_ /= v; + lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ / v; return std::forward(lhs); } @@ -489,7 +490,8 @@ public: friend constexpr decltype(auto) operator/=(Q1&& lhs, const Q2& rhs) { MP_UNITS_EXPECTS_DEBUG(rhs != rhs.zero()); - lhs.numerical_value_is_an_implementation_detail_ /= rhs.numerical_value_is_an_implementation_detail_; + lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ + / rhs.numerical_value_is_an_implementation_detail_; return std::forward(lhs); } From 5d3ed201b6db8d45d4a5ccbcacfd67cbab139e29 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:48:31 +0200 Subject: [PATCH 04/44] [msvc][fix] some short names hide global identifier --- src/core/include/mp-units/framework/quantity_concepts.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/include/mp-units/framework/quantity_concepts.h b/src/core/include/mp-units/framework/quantity_concepts.h index 37929f19..38403569 100644 --- a/src/core/include/mp-units/framework/quantity_concepts.h +++ b/src/core/include/mp-units/framework/quantity_concepts.h @@ -41,7 +41,7 @@ void to_base_specialization_of_quantity(const volatile quantity*); template inline constexpr bool is_derived_from_specialization_of_quantity = - requires(T* t) { to_base_specialization_of_quantity(t); }; + requires(T* type) { to_base_specialization_of_quantity(type); }; } // namespace detail From 30ac2882bdb2e0247b7f535dffd51bbf2cb71ae3 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:12:10 +0200 Subject: [PATCH 05/44] [msvc][fix] a lot of brackets where msvc prefers the type and not the value. (Issue reported) --- example/avg_speed.cpp | 12 +- example/capacitor_time_curve.cpp | 2 +- example/clcpp_response.cpp | 4 +- .../include/glide_computer_lib.h | 2 +- example/hello_units.cpp | 2 +- example/include/geographic.h | 8 +- example/kalman_filter/kalman.h | 16 +- example/spectroscopy_units.cpp | 8 +- example/storage_tank.cpp | 10 +- example/total_energy.cpp | 4 +- .../include/mp-units/systems/si/chrono.h | 4 +- .../include/mp-units/systems/si/math.h | 14 +- test/static/chrono_test.cpp | 62 +- test/static/concepts_test.cpp | 267 +++---- test/static/custom_rep_test_min_impl.cpp | 62 +- test/static/quantity_point_test.cpp | 682 +++++++++--------- test/static/quantity_test.cpp | 172 ++--- test/static/reference_test.cpp | 2 +- test/static/si_test.cpp | 2 +- 19 files changed, 680 insertions(+), 655 deletions(-) diff --git a/example/avg_speed.cpp b/example/avg_speed.cpp index dc2d24d2..11072bb3 100644 --- a/example/avg_speed.cpp +++ b/example/avg_speed.cpp @@ -45,26 +45,26 @@ namespace { using namespace mp_units; -constexpr quantity fixed_int_si_avg_speed(quantity d, - quantity t) +constexpr quantity fixed_int_si_avg_speed(quantity<(si::metre), int> d, + quantity<(si::second), int> t) { return d / t; } -constexpr quantity fixed_double_si_avg_speed(quantity d, quantity t) +constexpr quantity fixed_double_si_avg_speed(quantity<(si::metre)> d, quantity<(si::second)> t) { return d / t; } -constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) +constexpr QuantityOf<(isq::speed)> auto avg_speed(QuantityOf<(isq::length)> auto d, QuantityOf<(isq::time)> auto t) { return d / t; } -template D, QuantityOf T, QuantityOf V> +template D, QuantityOf<(isq::time)> T, QuantityOf<(isq::speed)> V> void print_result(D distance, T duration, V speed) { - const auto result_in_kmph = speed.force_in(si::kilo / non_si::hour); + const auto result_in_kmph = speed.force_in((si::kilo<(si::metre)> / non_si::hour)); std::cout << "Average speed of a car that makes " << distance << " in " << duration << " is " << result_in_kmph << ".\n"; } diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp index 4cf363fe..2f2f7fdb 100644 --- a/example/capacitor_time_curve.cpp +++ b/example/capacitor_time_curve.cpp @@ -48,7 +48,7 @@ int main() constexpr auto RR = isq::resistance(4.7 * si::kilo); for (auto tt = 0 * ms; tt <= 50 * ms; ++tt) { - const QuantityOf auto Vt = V0 * exp(dimensionless(-tt / (RR * CC))); + const QuantityOf<(isq::voltage)> auto Vt = V0 * exp(dimensionless(-tt / (RR * CC))); // TODO try to make the below work instead // const QuantityOf auto Vt = V0 * exp(-tt / (RR * CC)); diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index 42ed6d0b..9a74de52 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -44,8 +44,8 @@ void simple_quantities() using namespace mp_units::si; using namespace mp_units::international; - using distance = quantity]>; - using duration = quantity; + using distance = quantity<(isq::distance[kilo])>; + using duration = quantity<(isq::duration[second])>; constexpr distance km = 1. * kilo; constexpr distance miles = 1. * mile; diff --git a/example/glide_computer_lib/include/glide_computer_lib.h b/example/glide_computer_lib/include/glide_computer_lib.h index 5e2ac4db..e8fafbf3 100644 --- a/example/glide_computer_lib/include/glide_computer_lib.h +++ b/example/glide_computer_lib/include/glide_computer_lib.h @@ -90,7 +90,7 @@ struct glider { std::array polar; }; -constexpr mp_units::QuantityOf auto glide_ratio(const glider::polar_point& polar) +constexpr mp_units::QuantityOf<(mp_units::dimensionless)> auto glide_ratio(const glider::polar_point& polar) { return polar.v / -polar.climb; } diff --git a/example/hello_units.cpp b/example/hello_units.cpp index e635bc25..95b5e6d6 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -45,7 +45,7 @@ import mp_units; using namespace mp_units; -constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) +constexpr QuantityOf<(isq::speed)> auto avg_speed(QuantityOf<(isq::length)> auto d, QuantityOf<(isq::time)> auto t) { return d / t; } diff --git a/example/include/geographic.h b/example/include/geographic.h index ba26b3f1..4f7ca94a 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -79,10 +79,10 @@ inline constexpr struct prime_meridian final : mp_units::absolute_point_origin -using latitude = mp_units::quantity_point>; +using latitude = mp_units::quantity_point<(mp_units::si::degree), equator, ranged_representation>; template -using longitude = mp_units::quantity_point>; +using longitude = mp_units::quantity_point<(mp_units::si::degree), prime_meridian, ranged_representation>; template std::basic_ostream& operator<<(std::basic_ostream& os, const latitude& lat) @@ -176,7 +176,7 @@ template distance spherical_distance(position from, position to) { using namespace mp_units; - constexpr quantity earth_radius = 6'371 * isq::radius[si::kilo]; + constexpr quantity earth_radius = 6'371 * isq::radius[si::kilo<(si::metre)>]; using si::sin, si::cos, si::asin, si::acos; @@ -193,7 +193,7 @@ distance spherical_distance(position from, position to) // const auto central_angle = 2 * asin(sqrt(0.5 - cos(to_lat - from_lat) / 2 + cos(from_lat) * cos(to_lat) * (1 // - cos(lon2_rad - from_lon)) / 2)); - return quantity_cast(earth_radius * central_angle); + return quantity_cast<(isq::distance)>(earth_radius * central_angle); } else { // the haversine formula const quantity sin_lat = sin((to_lat - from_lat) / 2); diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index 6e629477..e959e3d3 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -116,15 +116,15 @@ template } // state update -template K> +template K> requires(implicitly_convertible(QM::quantity_spec, QP::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, K gain) { return system_state{get<0>(predicted) + gain * (measured - get<0>(predicted))}; } -template K, - mp_units::QuantityOf T> +template K, + mp_units::QuantityOf<(mp_units::isq::time)> T> requires(implicitly_convertible(QM::quantity_spec, QP1::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, std::array gain, T interval) @@ -135,7 +135,7 @@ template K, mp_units::QuantityOf T> + mp_units::QuantityOf<(mp_units::dimensionless)> K, mp_units::QuantityOf<(mp_units::isq::time)> T> requires(implicitly_convertible(QM::quantity_spec, QP1::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, std::array gain, T interval) @@ -147,13 +147,13 @@ template K> +template K> [[nodiscard]] constexpr Q covariance_update(Q uncertainty, K gain) { return (1 * mp_units::one - gain) * uncertainty; } -template K> +template K> [[nodiscard]] constexpr system_state_estimate state_estimate_update( const system_state_estimate& previous, QP measurement, K gain) { @@ -162,7 +162,7 @@ template T> +template T> [[nodiscard]] constexpr system_state state_extrapolation(const system_state& estimated, T interval) { auto to_quantity = [](const auto& qp) { return qp.quantity_ref_from(qp.point_origin); }; @@ -171,7 +171,7 @@ template T return system_state{qp1, qp2}; } -template T> +template T> [[nodiscard]] constexpr system_state state_extrapolation(const system_state& estimated, T interval) { diff --git a/example/spectroscopy_units.cpp b/example/spectroscopy_units.cpp index 3fce6a8b..d618b3b3 100644 --- a/example/spectroscopy_units.cpp +++ b/example/spectroscopy_units.cpp @@ -54,8 +54,8 @@ constexpr auto h = 1 * si::si2019::planck_constant; constexpr auto kb = 1 * si::si2019::boltzmann_constant; // prints quantities in the resulting unit -template T1, QuantityOf T2, QuantityOf T3, - QuantityOf T4, QuantityOf T5> +template T1, QuantityOf<(isq::wavenumber)> T2, QuantityOf<(isq::frequency)> T3, + QuantityOf<(isq::thermodynamic_temperature)> T4, QuantityOf<(isq::wavelength)> T5> void print_line(const std::tuple& t) { std::cout << MP_UNITS_STD_FMT::format( @@ -65,8 +65,8 @@ void print_line(const std::tuple& t) // prints quantities in semi-SI units // (eV is not an official SI unit) -template T1, QuantityOf T2, QuantityOf T3, - QuantityOf T4, QuantityOf T5> +template T1, QuantityOf<(isq::wavenumber)> T2, QuantityOf<(isq::frequency)> T3, + QuantityOf<(isq::thermodynamic_temperature)> T4, QuantityOf<(isq::wavelength)> T5> void print_line_si(const std::tuple& t) { std::cout << MP_UNITS_STD_FMT::format( diff --git a/example/storage_tank.cpp b/example/storage_tank.cpp index ad9f7580..9e2c1020 100644 --- a/example/storage_tank.cpp +++ b/example/storage_tank.cpp @@ -77,10 +77,10 @@ public: density_ = density; } - [[nodiscard]] constexpr QuantityOf auto filled_weight() const + [[nodiscard]] constexpr QuantityOf<(isq::weight)> auto filled_weight() const { const auto volume = isq::volume(base_ * height_); // TODO check if we can remove that cast - const QuantityOf auto mass = density_ * volume; + const QuantityOf<(isq::mass)> auto mass = density_ * volume; return isq::weight(mass * g); } @@ -130,9 +130,9 @@ int main() const quantity spare_capacity = tank.spare_capacity(measured_mass); const quantity filled_weight = tank.filled_weight(); - const QuantityOf auto input_flow_rate = measured_mass / fill_time; - const QuantityOf auto float_rise_rate = fill_level / fill_time; - const QuantityOf auto fill_time_left = (height / fill_level - 1 * one) * fill_time; + const QuantityOf<(isq::mass_change_rate)> auto input_flow_rate = measured_mass / fill_time; + const QuantityOf<(isq::speed)> auto float_rise_rate = fill_level / fill_time; + const QuantityOf<(isq::time)> auto fill_time_left = (height / fill_level - 1 * one) * fill_time; const quantity fill_ratio = fill_level / height; diff --git a/example/total_energy.cpp b/example/total_energy.cpp index bcd149d6..95d23f31 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -45,8 +45,8 @@ namespace { using namespace mp_units; -QuantityOf auto total_energy(QuantityOf auto p, QuantityOf auto m, - QuantityOf auto c) +QuantityOf<(isq::mechanical_energy)> auto total_energy(QuantityOf<(isq::momentum)> auto p, QuantityOf<(isq::mass)> auto m, + QuantityOf<(isq::speed)> auto c) { return isq::mechanical_energy(sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c)))); } diff --git a/src/systems/include/mp-units/systems/si/chrono.h b/src/systems/include/mp-units/systems/si/chrono.h index fa878269..0fad31e1 100644 --- a/src/systems/include/mp-units/systems/si/chrono.h +++ b/src/systems/include/mp-units/systems/si/chrono.h @@ -127,13 +127,13 @@ namespace detail { } // namespace detail -template Q> +template Q> [[nodiscard]] constexpr auto to_chrono_duration(const Q& q) { return std::chrono::duration{q}; } -template QP> +template QP> requires is_specialization_of, chrono_point_origin_> [[nodiscard]] constexpr auto to_chrono_time_point(const QP& qp) { diff --git a/src/systems/include/mp-units/systems/si/math.h b/src/systems/include/mp-units/systems/si/math.h index b3d9b483..202ea76d 100644 --- a/src/systems/include/mp-units/systems/si/math.h +++ b/src/systems/include/mp-units/systems/si/math.h @@ -43,7 +43,7 @@ import std; MP_UNITS_EXPORT namespace mp_units::si { -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { sin(v); } || requires(Rep v) { std::sin(v); } [[nodiscard]] inline QuantityOf auto sin(const quantity& q) noexcept { @@ -57,7 +57,7 @@ template auto R, typename Rep> return quantity{sin(q.numerical_value_in(radian)), one}; } -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { cos(v); } || requires(Rep v) { std::cos(v); } [[nodiscard]] inline QuantityOf auto cos(const quantity& q) noexcept { @@ -71,7 +71,7 @@ template auto R, typename Rep> return quantity{cos(q.numerical_value_in(radian)), one}; } -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { tan(v); } || requires(Rep v) { std::tan(v); } [[nodiscard]] inline QuantityOf auto tan(const quantity& q) noexcept { @@ -87,7 +87,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { asin(v); } || requires(Rep v) { std::asin(v); } -[[nodiscard]] inline QuantityOf auto asin(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto asin(const quantity& q) noexcept { using std::asin; if constexpr (!treat_as_floating_point) { @@ -101,7 +101,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { acos(v); } || requires(Rep v) { std::acos(v); } -[[nodiscard]] inline QuantityOf auto acos(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto acos(const quantity& q) noexcept { using std::acos; if constexpr (!treat_as_floating_point) { @@ -115,7 +115,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { atan(v); } || requires(Rep v) { std::atan(v); } -[[nodiscard]] inline QuantityOf auto atan(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto atan(const quantity& q) noexcept { using std::atan; if constexpr (!treat_as_floating_point) { @@ -132,7 +132,7 @@ template common_reference(R1, R2); requires requires { atan2(v1, v2); } || requires { std::atan2(v1, v2); }; } -[[nodiscard]] inline QuantityOf auto atan2(const quantity& y, +[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto atan2(const quantity& y, const quantity& x) noexcept { constexpr auto ref = common_reference(R1, R2); diff --git a/test/static/chrono_test.cpp b/test/static/chrono_test.cpp index 9f3b1901..a3a0d489 100644 --- a/test/static/chrono_test.cpp +++ b/test/static/chrono_test.cpp @@ -57,41 +57,41 @@ static_assert(!QuantityPoint); // construction - same rep type static_assert( - std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); + std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); static_assert( - std::constructible_from, sys_seconds>); + std::constructible_from, sys_seconds>); static_assert( - !std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(!std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(!std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert(!std::constructible_from, sys_seconds>); -static_assert(!std::convertible_to>); + !std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(!std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(!std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(!std::constructible_from, sys_seconds>); +static_assert(!std::convertible_to>); // construction - different rep type (integral to a floating-point) -static_assert(std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); static_assert(quantity{1s} == 1 * s); static_assert(quantity{1s} == 1 * s); diff --git a/test/static/concepts_test.cpp b/test/static/concepts_test.cpp index 06b20699..a419d8d4 100644 --- a/test/static/concepts_test.cpp +++ b/test/static/concepts_test.cpp @@ -83,7 +83,7 @@ inline constexpr auto speed = isq::length / isq::time; static_assert(QuantitySpec); static_assert(QuantitySpec); static_assert(QuantitySpec); -static_assert(QuantitySpec)>); +static_assert(QuantitySpec)>); static_assert(QuantitySpec); static_assert(QuantitySpec(isq::length))>); static_assert(QuantitySpec); @@ -95,7 +95,7 @@ static_assert(!QuantitySpec); static_assert(detail::NamedQuantitySpec); static_assert(detail::NamedQuantitySpec); static_assert(detail::NamedQuantitySpec); -static_assert(!detail::NamedQuantitySpec)>>); +static_assert(!detail::NamedQuantitySpec)>>); static_assert(!detail::NamedQuantitySpec); static_assert(!detail::NamedQuantitySpec(isq::length))>); static_assert(detail::NamedQuantitySpec); @@ -106,7 +106,7 @@ static_assert(!detail::NamedQuantitySpec); // DerivedQuantitySpec static_assert(!detail::DerivedQuantitySpec); static_assert(!detail::DerivedQuantitySpec); -static_assert(!detail::DerivedQuantitySpec)>); +static_assert(!detail::DerivedQuantitySpec)>); static_assert(!detail::DerivedQuantitySpec); static_assert(detail::DerivedQuantitySpec); static_assert(detail::DerivedQuantitySpec(isq::length))>); @@ -118,7 +118,7 @@ static_assert(!detail::DerivedQuantitySpec); // QuantityKindSpec static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec); -static_assert(detail::QuantityKindSpec)>>); +static_assert(detail::QuantityKindSpec)>>); static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec(isq::length))>); @@ -133,7 +133,7 @@ static_assert(!detail::QuantityKindSpec); // Unit static_assert(Unit); static_assert(Unit); -static_assert(Unit)>); +static_assert(Unit)>); static_assert(Unit); static_assert(Unit); static_assert(Unit); @@ -144,22 +144,47 @@ static_assert(Unit); static_assert(Unit, struct si::second>>); static_assert(Unit>>); static_assert(Unit); -static_assert(!Unit>>); +static_assert(!Unit>>); static_assert(!Unit>); static_assert(!Unit>); -static_assert(!Unit>>); -static_assert(!Unit, si::second>>); +static_assert(!Unit>>); +static_assert(!Unit, (si::second)>>); static_assert(!Unit); static_assert(!Unit); #if MP_UNITS_HOSTED static_assert(!Unit); #endif +// NamedUnit +static_assert(detail::NamedUnit); +static_assert(detail::NamedUnit); +static_assert(!detail::NamedUnit); +static_assert(!detail::NamedUnit))>); +static_assert(!detail::NamedUnit); +static_assert(!detail::NamedUnit); +static_assert(!detail::NamedUnit * si::second)>); +static_assert(!detail::NamedUnit); +static_assert(!detail::NamedUnit(si::metre))>); +static_assert(detail::NamedUnit); +static_assert(!detail::NamedUnit, struct si::second>>); +static_assert(!detail::NamedUnit>>); +static_assert(!detail::NamedUnit); +static_assert(!detail::NamedUnit>>); +static_assert(!detail::NamedUnit>); +static_assert(!detail::NamedUnit>); +static_assert(!detail::NamedUnit>>); +static_assert(!detail::NamedUnit, (si::second)>>); +static_assert(!detail::NamedUnit); +static_assert(!detail::NamedUnit); +#if MP_UNITS_HOSTED +static_assert(!detail::NamedUnit); +#endif + // PrefixableUnit static_assert(PrefixableUnit); static_assert(PrefixableUnit); static_assert(!PrefixableUnit); -static_assert(!PrefixableUnit)>); +static_assert(!PrefixableUnit)>); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit * si::second)>); @@ -169,11 +194,11 @@ static_assert(PrefixableUnit); static_assert(!PrefixableUnit, struct si::second>>); static_assert(!PrefixableUnit>>); static_assert(!PrefixableUnit); -static_assert(!PrefixableUnit>>); +static_assert(!PrefixableUnit>>); static_assert(!PrefixableUnit>); static_assert(!PrefixableUnit>); -static_assert(!PrefixableUnit>>); -static_assert(!PrefixableUnit, si::second>>); +static_assert(!PrefixableUnit>>); +static_assert(!PrefixableUnit, (si::second)>>); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit); #if MP_UNITS_HOSTED @@ -184,7 +209,7 @@ static_assert(!PrefixableUnit); static_assert(AssociatedUnit); static_assert(!AssociatedUnit); static_assert(AssociatedUnit); -static_assert(AssociatedUnit)>); +static_assert(AssociatedUnit)>); static_assert(AssociatedUnit); static_assert(AssociatedUnit); static_assert(AssociatedUnit * si::second)>); @@ -194,11 +219,11 @@ static_assert(AssociatedUnit); static_assert(AssociatedUnit, struct si::second>>); static_assert(AssociatedUnit>>); static_assert(AssociatedUnit); -static_assert(!AssociatedUnit>>); +static_assert(!AssociatedUnit>>); static_assert(!AssociatedUnit>); static_assert(!AssociatedUnit>); -static_assert(!AssociatedUnit>>); -static_assert(!AssociatedUnit, si::second>>); +static_assert(!AssociatedUnit>>); +static_assert(!AssociatedUnit, (si::second)>>); static_assert(!AssociatedUnit); static_assert(!AssociatedUnit); #if MP_UNITS_HOSTED @@ -206,19 +231,19 @@ static_assert(!AssociatedUnit); #endif // UnitOf -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); static_assert(!UnitOf); -static_assert(!UnitOf); -static_assert(!UnitOf); +static_assert(!UnitOf); +static_assert(!UnitOf); // Reference static_assert(Reference); @@ -228,32 +253,32 @@ static_assert(Reference); static_assert(Reference); static_assert(!Reference); static_assert(!Reference); -static_assert(!Reference)>); +static_assert(!Reference)>); static_assert(!Reference); static_assert(!Reference); // ReferenceOf -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); static_assert(ReferenceOf); static_assert(ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(!ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(!ReferenceOf); // Representation static_assert(Representation); @@ -278,57 +303,57 @@ static_assert(!RepresentationOf); #endif // Quantity -static_assert(Quantity>); -static_assert(Quantity>); -static_assert(Quantity>); -static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); #if MP_UNITS_HOSTED static_assert(!Quantity); #endif -static_assert(!Quantity>); +static_assert(!Quantity>); static_assert(!Quantity); // QuantityOf -static_assert(QuantityOf, isq::length>); -static_assert(QuantityOf, isq::radius>); -static_assert(!QuantityOf, isq::length>); -static_assert(QuantityOf, isq::length>); -static_assert(!QuantityOf, isq::radius>); -static_assert(QuantityOf, isq::length>); -static_assert(QuantityOf, isq::radius>); -static_assert(!QuantityOf, isq::dim_length>); +static_assert(QuantityOf, (isq::length)>); +static_assert(QuantityOf, (isq::radius)>); +static_assert(!QuantityOf, (isq::length)>); +static_assert(QuantityOf, (isq::length)>); +static_assert(!QuantityOf, (isq::radius)>); +static_assert(QuantityOf, (isq::length)>); +static_assert(QuantityOf, (isq::radius)>); +static_assert(!QuantityOf, (isq::dim_length)>); static_assert(QuantityOf, dimensionless>); static_assert(QuantityOf, dimensionless>); -static_assert(QuantityOf, isq::rotation>); -static_assert(QuantityOf, dimensionless>); -static_assert(QuantityOf, isq::angular_measure>); -static_assert(!QuantityOf, dimensionless>); -static_assert(QuantityOf, isq::angular_measure>); -static_assert(!QuantityOf, dimensionless>); -static_assert(QuantityOf, isq::rotation>); -static_assert(QuantityOf, isq::angular_measure>); -static_assert(!QuantityOf, isq::rotation>); -static_assert(!QuantityOf, isq::angular_measure>); +static_assert(QuantityOf, (isq::rotation)>); +static_assert(QuantityOf, dimensionless>); +static_assert(QuantityOf, (isq::angular_measure)>); +static_assert(!QuantityOf, dimensionless>); +static_assert(QuantityOf, (isq::angular_measure)>); +static_assert(!QuantityOf, dimensionless>); +static_assert(QuantityOf, (isq::rotation)>); +static_assert(QuantityOf, (isq::angular_measure)>); +static_assert(!QuantityOf, (isq::rotation)>); +static_assert(!QuantityOf, (isq::angular_measure)>); // QuantityLike #if MP_UNITS_HOSTED static_assert(QuantityLike); static_assert(QuantityLike); #endif -static_assert(!QuantityLike>); -static_assert(!QuantityLike>); +static_assert(!QuantityLike>); +static_assert(!QuantityLike>); static_assert(!QuantityLike); // QuantityPoint -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); static_assert(!QuantityPoint); -static_assert(!QuantityPoint>); +static_assert(!QuantityPoint>); static_assert(!QuantityPoint); static_assert(!QuantityPoint); #if MP_UNITS_HOSTED @@ -338,35 +363,35 @@ static_assert(!QuantityPoint> static_assert(!QuantityPoint); // QuantityPointOf -static_assert(QuantityPointOf, isq::length>); -static_assert(QuantityPointOf, isq::radius>); -static_assert(QuantityPointOf, isq::length>); -static_assert(!QuantityPointOf, isq::radius>); -static_assert(QuantityPointOf, isq::length>); -static_assert(QuantityPointOf, isq::radius>); -static_assert(QuantityPointOf, isq::length>); -static_assert(QuantityPointOf, isq::radius>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, (isq::length)>); +static_assert(QuantityPointOf, (isq::radius)>); +static_assert(QuantityPointOf, (isq::length)>); +static_assert(!QuantityPointOf, (isq::radius)>); +static_assert(QuantityPointOf, (isq::length)>); +static_assert(QuantityPointOf, (isq::radius)>); +static_assert(QuantityPointOf, (isq::length)>); +static_assert(QuantityPointOf, (isq::radius)>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); // PointOrigin static_assert(PointOrigin); static_assert(PointOrigin); -static_assert(!PointOrigin>); +static_assert(!PointOrigin>); static_assert(!PointOrigin>); -static_assert(!PointOrigin>); -static_assert(!PointOrigin>); -static_assert(!PointOrigin>); +static_assert(!PointOrigin>); +static_assert(!PointOrigin>); +static_assert(!PointOrigin>); static_assert(!PointOrigin); #if MP_UNITS_HOSTED static_assert(!PointOrigin); @@ -375,38 +400,38 @@ static_assert(!PointOrigin>); static_assert(!PointOrigin); // PointOriginFor -static_assert(PointOriginFor); -static_assert(PointOriginFor); -static_assert(!PointOriginFor); -static_assert(PointOriginFor); -static_assert(PointOriginFor); -static_assert(!PointOriginFor); -static_assert(!PointOriginFor, isq::length>); -static_assert(!PointOriginFor, isq::radius>); -static_assert(!PointOriginFor, isq::time>); -static_assert(!PointOriginFor, isq::length>); -static_assert(!PointOriginFor, isq::radius>); -static_assert(!PointOriginFor, isq::time>); -static_assert(!PointOriginFor, isq::length>); -static_assert(!PointOriginFor, isq::radius>); -static_assert(!PointOriginFor, isq::time>); -static_assert(!PointOriginFor, isq::length>); -static_assert(!PointOriginFor, isq::radius>); -static_assert(!PointOriginFor, isq::time>); -static_assert(!PointOriginFor); +static_assert(PointOriginFor); +static_assert(PointOriginFor); +static_assert(!PointOriginFor); +static_assert(PointOriginFor); +static_assert(PointOriginFor); +static_assert(!PointOriginFor); +static_assert(!PointOriginFor, (isq::length)>); +static_assert(!PointOriginFor, (isq::radius)>); +static_assert(!PointOriginFor, (isq::time)>); +static_assert(!PointOriginFor, (isq::length)>); +static_assert(!PointOriginFor, (isq::radius)>); +static_assert(!PointOriginFor, (isq::time)>); +static_assert(!PointOriginFor, (isq::length)>); +static_assert(!PointOriginFor, (isq::radius)>); +static_assert(!PointOriginFor, (isq::time)>); +static_assert(!PointOriginFor, (isq::length)>); +static_assert(!PointOriginFor, (isq::radius)>); +static_assert(!PointOriginFor, (isq::time)>); +static_assert(!PointOriginFor); #if MP_UNITS_HOSTED -static_assert(!PointOriginFor); -static_assert(!PointOriginFor, isq::length>); +static_assert(!PointOriginFor); +static_assert(!PointOriginFor, (isq::length)>); #endif -static_assert(!PointOriginFor); +static_assert(!PointOriginFor); // QuantityPointLike #if MP_UNITS_HOSTED static_assert(QuantityPointLike>); static_assert(!QuantityPointLike); #endif -static_assert(!QuantityPointLike>); -static_assert(!QuantityPointLike>); +static_assert(!QuantityPointLike>); +static_assert(!QuantityPointLike>); static_assert(!QuantityPointLike); } // namespace diff --git a/test/static/custom_rep_test_min_impl.cpp b/test/static/custom_rep_test_min_impl.cpp index 8e8c3b7c..ccff6080 100644 --- a/test/static/custom_rep_test_min_impl.cpp +++ b/test/static/custom_rep_test_min_impl.cpp @@ -78,18 +78,18 @@ static_assert(Representation>); static_assert(Representation>); // construction from a value is not allowed -static_assert(!std::constructible_from>, min_impl>); -static_assert(!std::convertible_to, quantity>>); +static_assert(!std::constructible_from>, min_impl>); +static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); -static_assert(!std::constructible_from>, min_impl>); -static_assert(!std::convertible_to, quantity>>); +static_assert(!std::constructible_from>, min_impl>); +static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); // multiply syntax should work template concept creates_quantity = Unit && requires { T{} * U; }; -static_assert(creates_quantity, si::metre>); -static_assert(creates_quantity, si::metre>); +static_assert(creates_quantity, (si::metre)>); +static_assert(creates_quantity, (si::metre)>); // multiply syntax static_assert(creates_quantity, one>); @@ -99,46 +99,46 @@ static_assert(creates_quantity, percent>); // construction from a quantity // min_impl -> min_impl -static_assert(std::constructible_from>, quantity>>); -static_assert(std::convertible_to>, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); -static_assert(std::constructible_from>, quantity>>); -static_assert(std::convertible_to>, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); -static_assert(std::constructible_from>, quantity>>); -static_assert(std::convertible_to>, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); -static_assert(!std::constructible_from>, - quantity>>); // narrowing conversion -static_assert(!std::convertible_to>, quantity>>); +static_assert(!std::constructible_from>, + quantity<(si::metre), min_impl>>); // narrowing conversion +static_assert(!std::convertible_to>, quantity<(si::metre), min_impl>>); // T -> min_impl -static_assert(std::constructible_from>, quantity>); -static_assert(std::convertible_to, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), int>>); +static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); -static_assert(std::constructible_from>, quantity>); -static_assert(std::convertible_to, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), double>>); +static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); -static_assert(std::constructible_from>, quantity>); -static_assert(std::convertible_to, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), int>>); +static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); static_assert( - !std::constructible_from>, quantity>); // narrowing conversion -static_assert(!std::convertible_to, quantity>>); + !std::constructible_from>, quantity<(si::metre), double>>); // narrowing conversion +static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); // min_impl -> T -static_assert(std::constructible_from, quantity>>); -static_assert(std::convertible_to>, quantity>); +static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), int>>); -static_assert(std::constructible_from, quantity>>); -static_assert(std::convertible_to>, quantity>); +static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), double>>); -static_assert(std::constructible_from, quantity>>); -static_assert(std::convertible_to>, quantity>); +static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), double>>); static_assert( - !std::constructible_from, quantity>>); // narrowing conversion -static_assert(!std::convertible_to>, quantity>); + !std::constructible_from, quantity<(si::metre), min_impl>>); // narrowing conversion +static_assert(!std::convertible_to>, quantity<(si::metre), int>>); // arithmetic operators diff --git a/test/static/quantity_point_test.cpp b/test/static/quantity_point_test.cpp index 06ad1f16..64254d3e 100644 --- a/test/static/quantity_point_test.cpp +++ b/test/static/quantity_point_test.cpp @@ -58,24 +58,24 @@ inline constexpr struct mean_sea_level final : absolute_point_origin { +inline constexpr struct same_mean_sea_level final : relative_point_origin { } same_mean_sea_level; -inline constexpr struct ground_level final : relative_point_origin { +inline constexpr struct ground_level final : relative_point_origin { } ground_level; inline constexpr auto my_ground_level = ground_level; -inline constexpr struct same_ground_level1 final : relative_point_origin { +inline constexpr struct same_ground_level1 final : relative_point_origin { } same_ground_level1; -inline constexpr struct same_ground_level2 final : relative_point_origin { +inline constexpr struct same_ground_level2 final : relative_point_origin { } same_ground_level2; -inline constexpr struct tower_peak final : relative_point_origin { +inline constexpr struct tower_peak final : relative_point_origin { } tower_peak; -inline constexpr struct other_ground_level final : relative_point_origin { +inline constexpr struct other_ground_level final : relative_point_origin { } other_ground_level; inline constexpr struct other_absolute_level final : absolute_point_origin { @@ -152,10 +152,10 @@ static_assert(zeroth_point_origin != zeroth_point_origin) == sizeof(double)); -static_assert(sizeof(quantity_point) == sizeof(double)); -static_assert(sizeof(quantity_point) == sizeof(short)); -static_assert(sizeof(quantity_point) == sizeof(short)); +static_assert(sizeof(quantity_point<(si::metre), mean_sea_level>) == sizeof(double)); +static_assert(sizeof(quantity_point<(isq::height[m]), mean_sea_level>) == sizeof(double)); +static_assert(sizeof(quantity_point<(si::metre), ground_level, short>) == sizeof(short)); +static_assert(sizeof(quantity_point<(isq::height[m]), ground_level, short>) == sizeof(short)); template typename QP> concept invalid_types = requires { @@ -188,15 +188,15 @@ static_assert(invalid_types); template typename QP> concept valid_types = requires { - typename QP; - typename QP; - typename QP; - typename QP; - typename QP; - typename QP; - typename QP, int>; - typename QP>, int>; - typename QP, int>; + typename QP<(si::metre), mean_sea_level, int>; + typename QP<(isq::height[m]), mean_sea_level, int>; + typename QP<(special_height[m]), mean_sea_level, int>; + typename QP<(si::metre), ground_level, int>; + typename QP<(isq::height[m]), ground_level, int>; + typename QP<(special_height[m]), ground_level, int>; + typename QP<(isq::height[m]), zeroth_point_origin<(isq::length)>, int>; + typename QP<(isq::height[m]), zeroth_point_origin>, int>; + typename QP<(si::metre), zeroth_point_origin<(isq::height)>, int>; }; static_assert(valid_types); @@ -217,14 +217,14 @@ static_assert(std::is_nothrow_destructible_v>); static_assert(std::is_standard_layout_v>); -static_assert(std::default_initializable>); -static_assert(std::move_constructible>); -static_assert(std::copy_constructible>); -static_assert(std::equality_comparable>); -static_assert(std::totally_ordered>); -static_assert(std::regular>); +static_assert(std::default_initializable>); +static_assert(std::move_constructible>); +static_assert(std::copy_constructible>); +static_assert(std::equality_comparable>); +static_assert(std::totally_ordered>); +static_assert(std::regular>); -static_assert(std::three_way_comparable>); +static_assert(std::three_way_comparable>); ////////////////// @@ -235,51 +235,51 @@ static_assert(quantity_point::reference == si::metre); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, zeroth_point_origin_>>); -static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>>); +static_assert(is_of_type::point_origin, zeroth_point_origin_>>); +static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, zeroth_point_origin_>); -static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>); +static_assert(is_of_type::point_origin, zeroth_point_origin_>); +static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>); static_assert(quantity_point::reference == si::metre); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct mean_sea_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct mean_sea_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct mean_sea_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct mean_sea_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct ground_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct ground_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct tower_peak>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct tower_peak>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == si::kelvin); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, struct si::absolute_zero>); +static_assert(is_of_type::point_origin, struct si::absolute_zero>); static_assert( - is_of_type::absolute_point_origin, struct si::absolute_zero>); + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == isq::thermodynamic_temperature[si::kelvin]); @@ -288,10 +288,10 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, +static_assert(is_of_type::point_origin, struct si::absolute_zero>); static_assert( - is_of_type::absolute_point_origin, + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == @@ -301,9 +301,9 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, +static_assert(is_of_type::point_origin, struct si::absolute_zero>); -static_assert(is_of_type::absolute_point_origin, +static_assert(is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == si::degree_Celsius); @@ -311,9 +311,9 @@ static_assert(quantity_point::quantity_spec = kind_of); static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::degree_Celsius); -static_assert(is_of_type::point_origin, struct si::ice_point>); +static_assert(is_of_type::point_origin, struct si::ice_point>); static_assert( - is_of_type::absolute_point_origin, struct si::absolute_zero>); + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == isq::Celsius_temperature[si::degree_Celsius]); @@ -322,10 +322,10 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::degree_Celsius); -static_assert(is_of_type::point_origin, +static_assert(is_of_type::point_origin, struct si::ice_point>); static_assert( - is_of_type::absolute_point_origin, + is_of_type::absolute_point_origin, struct si::absolute_zero>); @@ -333,18 +333,18 @@ static_assert( // member types ////////////////// -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, int>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, int>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, int>); +static_assert(is_same_v::rep, int>); static_assert( - is_same_v::quantity_type, quantity>); + is_same_v::quantity_type, quantity>); //////////////////////////// @@ -371,11 +371,11 @@ static_assert( ////////////////////////////// // there is no construction from a value -static_assert(!std::constructible_from, double>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, double>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, int>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, int>); +static_assert(!std::convertible_to>); static_assert(!std::constructible_from, double>); static_assert(!std::convertible_to>); @@ -396,135 +396,135 @@ static_assert(!std::convertible_to, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(si::metre)>>); +static_assert(!std::convertible_to, quantity_point<(si::metre)>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(si::metre)>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(si::metre)>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::speed[m / s])>>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::speed[m / s])>>); +static_assert(!std::convertible_to, quantity_point<(isq::length[m] / isq::time[s])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::length[m] / isq::time[s])>>); +static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); static_assert(std::constructible_from, quantity>); static_assert(!std::convertible_to, quantity_point>); // different dimensions -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(si::second)>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // convertible but different quantity_specs -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::length[m])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(special_height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::width[m])>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::width[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::length[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); #if MP_UNITS_HOSTED // quantity-like -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); #endif // ---------------------- // explicit point origins // ---------------------- -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(si::metre)>>); +static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(si::metre)>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); static_assert(!std::constructible_from, quantity>); static_assert(!std::convertible_to, quantity_point>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::width[m]), zeroth_length>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::width[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), zeroth_length>>); // different dimensions -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(si::second)>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::length[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); // not-compatible origin -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::length[m])>>); +static_assert(!std::convertible_to, quantity_point<((si::metre)), mean_sea_level>>); #if MP_UNITS_HOSTED // quantity-like -static_assert(!std::constructible_from>, +static_assert(!std::constructible_from>, std::chrono::seconds>); static_assert(!std::convertible_to>>); + quantity_point<(si::second), chrono_point_origin>>); -static_assert(!std::constructible_from>, +static_assert(!std::constructible_from>, std::chrono::seconds>); static_assert(!std::convertible_to>>); + quantity_point<(isq::time[s]), chrono_point_origin>>); static_assert( - !std::constructible_from>, + !std::constructible_from>, std::chrono::seconds>); static_assert( !std::convertible_to>>); + quantity_point<(isq::period_duration[s]), chrono_point_origin>>); #endif @@ -533,140 +533,140 @@ static_assert( /////////////////////////////////////// // implicit origin -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point<(si::metre)>>); +static_assert(std::convertible_to, quantity_point<(si::metre)>>); +static_assert(std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(std::convertible_to, quantity_point<(isq::height[m])>>); -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(std::convertible_to, quantity_point<(si::metre)>>); +static_assert(std::constructible_from, quantity_point<(si::metre)>>); +static_assert(std::convertible_to, quantity_point<(isq::height[m])>>); static_assert( - std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); + std::constructible_from, quantity_point<(isq::speed[m / s])>>); +static_assert(std::convertible_to, quantity_point<(isq::length[m]) / isq::time[s]>>); -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point<(isq::speed[m / s])>>); +static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point<(isq::length[m]) / isq::time[s]>>); +static_assert(std::convertible_to, quantity_point>); // convertible but different quantity_specs -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::length[m])>>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::width[m])>>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(isq::width[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(isq::length[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point>); // mixed origins -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(si::metre)>>); +static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); +static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); +static_assert(!std::convertible_to, quantity_point<(si::metre)>>); +static_assert(!std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // same explicit origins static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert(std::constructible_from, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::constructible_from, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[km]), mean_sea_level>>); -static_assert(std::constructible_from, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[km]), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::constructible_from, +static_assert(std::constructible_from, quantity_point>); static_assert(std::convertible_to, - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); + std::constructible_from, quantity_point<(si::metre), ground_level>>); +static_assert(std::convertible_to, quantity_point<(si::metre), ground_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(isq::height[m]), ground_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); -static_assert(std::constructible_from, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[km]), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(isq::height[km]), ground_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(isq::height[m]), ground_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(si::metre), ground_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(si::metre), ground_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); -static_assert(std::constructible_from, +static_assert(std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); static_assert( - std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); + std::constructible_from, quantity_point<(si::metre), ground_level>>); +static_assert(std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); + std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); +static_assert(std::convertible_to, quantity_point<(si::metre), ground_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(si::metre), other_ground_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(si::metre), ground_level>>); static_assert( std::constructible_from, quantity_point>); @@ -682,121 +682,121 @@ static_assert( static_assert( std::convertible_to, quantity_point>); -static_assert(std::constructible_from, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), zeroth_length>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::length[m]), zeroth_length>>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, - quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), zeroth_length>>); static_assert( - !std::convertible_to, quantity_point>); + !std::convertible_to, quantity_point<(isq::width[m]), zeroth_length>>); -static_assert(!std::constructible_from, - quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(isq::width[m]), zeroth_length>>); static_assert( - !std::convertible_to, quantity_point>); + !std::convertible_to, quantity_point<(isq::height[m]), zeroth_length>>); // different dimensions static_assert( - !std::constructible_from, quantity_point>); + !std::constructible_from, quantity_point<(si::kelvin), (si::ice_point)>>); static_assert( - !std::convertible_to, quantity_point>); + !std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); // non-convertible quantity_specs static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::convertible_to, quantity_point>); // implicit conversion from another quantity point only if non-truncating // int -> double OK -static_assert(std::constructible_from, - quantity_point>); -static_assert(std::convertible_to, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level, int>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); // truncating double -> int not allowed -static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, - quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level, int>>); // kilometre -> metre OK -static_assert(std::constructible_from, - quantity_point>); -static_assert(std::convertible_to, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[km]), mean_sea_level, int>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level, int>>); // truncating metre -> kilometre not allowed -static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, - quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level, int>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[km]), mean_sea_level, int>>); // converting to double always OK -static_assert(std::constructible_from, - quantity_point>); -static_assert(std::convertible_to, - quantity_point>); -static_assert(std::constructible_from, - quantity_point>); -static_assert(std::convertible_to, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[km]), mean_sea_level, int>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level, int>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[km]), mean_sea_level>>); // same but not a default origin -static_assert(std::constructible_from, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::constructible_from, +static_assert(std::constructible_from, quantity_point>); static_assert(std::convertible_to, - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::convertible_to, quantity_point>); // different origins -static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, - quantity_point>); -static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, - quantity_point>); -static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, - quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), other_absolute_level>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), other_absolute_level>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), ground_level>>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), ground_level>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), other_absolute_level>>); #if MP_UNITS_HOSTED // quantity-point-like static_assert( - std::constructible_from>, sys_seconds>); + std::constructible_from>, sys_seconds>); static_assert( - std::convertible_to>>); + std::convertible_to>>); // incompatible origin static_assert( - !std::constructible_from>, sys_seconds>); + !std::constructible_from>, sys_seconds>); static_assert( - !std::convertible_to>>); + !std::convertible_to>>); #endif @@ -825,17 +825,17 @@ static_assert((mean_sea_level + 42 * m).quantity_from(mean_sea_level) == 42 * m) static_assert((ground_level + 42 * m).quantity_from(ground_level) == 42 * m); static_assert((tower_peak + 42 * m).quantity_from(tower_peak) == 42 * m); -static_assert(quantity_point(ground_level + 42 * m).quantity_from(mean_sea_level) == +static_assert(quantity_point<(isq::height[m]), mean_sea_level>(ground_level + 42 * m).quantity_from(mean_sea_level) == 84 * m); -static_assert(quantity_point(tower_peak + 42 * m).quantity_from(mean_sea_level) == +static_assert(quantity_point<(isq::height[m]), mean_sea_level>(tower_peak + 42 * m).quantity_from(mean_sea_level) == 126 * m); -static_assert(quantity_point(mean_sea_level + 84 * m).quantity_from(ground_level) == +static_assert(quantity_point<(isq::height[m]), ground_level>(mean_sea_level + 84 * m).quantity_from(ground_level) == 42 * m); -static_assert(quantity_point(tower_peak + 42 * m).quantity_from(ground_level) == 84 * m); +static_assert(quantity_point<(isq::height[m]), ground_level>(tower_peak + 42 * m).quantity_from(ground_level) == 84 * m); -static_assert(quantity_point(mean_sea_level + 42 * m).quantity_from(tower_peak) == -42 * m); -static_assert(quantity_point(ground_level + 84 * m).quantity_from(tower_peak) == 42 * m); +static_assert(quantity_point<(isq::height[m]), tower_peak>(mean_sea_level + 42 * m).quantity_from(tower_peak) == -42 * m); +static_assert(quantity_point<(isq::height[m]), tower_peak>(ground_level + 84 * m).quantity_from(tower_peak) == 42 * m); static_assert((mean_sea_level + 42 * m).point_for(mean_sea_level).quantity_from(mean_sea_level) == 42 * m); static_assert((ground_level + 42 * m).point_for(mean_sea_level).quantity_from(mean_sea_level) == 84 * m); @@ -850,7 +850,7 @@ static_assert((mean_sea_level + 42 * m).point_for(tower_peak).quantity_from(towe static_assert((ground_level + 84 * m).point_for(tower_peak).quantity_from(tower_peak) == 42 * m); static_assert(is_of_type<(ground_level + isq::height(short{42} * m)).point_for(mean_sea_level), - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); /////////////////////////////////// @@ -877,8 +877,8 @@ static_assert(is_of_type<(mean_sea_level + 2500. * m).force_in(km), quantit template typename QP> concept invalid_unit_conversion = requires { - requires !requires { QP(2000 * m).in(km); }; // truncating conversion - requires !requires { QP(2 * m).in(s); }; // invalid unit + requires !requires { QP<(isq::height[m]), mean_sea_level, int>(2000 * m).in(km); }; // truncating conversion + requires !requires { QP<(isq::height[m]), mean_sea_level, int>(2 * m).in(s); }; // invalid unit }; static_assert(invalid_unit_conversion); @@ -1020,18 +1020,18 @@ static_assert((mean_sea_level + 1123 * m -= 1 * km).quantity_from_zero().numeric template typename QP> concept invalid_compound_assignments = requires() { // truncating not allowed - requires !requires(QP l) { l += 2.5 * m; }; - requires !requires(QP l) { l -= 2.5 * m; }; - requires !requires(QP l) { l += 2 * isq::height[m]; }; - requires !requires(QP l) { l -= 2 * isq::height[m]; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += 2.5 * m; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= 2.5 * m; }; + requires !requires(QP l) { l += 2 * (isq::height[m]); }; + requires !requires(QP l) { l -= 2 * (isq::height[m]); }; // only quantities can be added or subtracted - requires !requires(QP l) { l += 2; }; - requires !requires(QP l) { l -= 2; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += 2; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= 2; }; // no unit constants - requires !requires(QP l) { l += m; }; - requires !requires(QP l) { l -= m; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += m; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= m; }; }; static_assert(invalid_compound_assignments); @@ -1174,36 +1174,36 @@ static_assert(is_of_type<1 * m + (mean_sea_level + 1 * km), quantity_point>); static_assert( - is_of_type<1 * m + (mean_sea_level + isq::height(1 * m)), quantity_point>); + is_of_type<1 * m + (mean_sea_level + isq::height(1 * m)), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<1 * m + (mean_sea_level + isq::height(1 * km)), quantity_point>); + is_of_type<1 * m + (mean_sea_level + isq::height(1 * km)), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<1 * km + (mean_sea_level + isq::height(1 * m)), quantity_point>); + is_of_type<1 * km + (mean_sea_level + isq::height(1 * m)), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type>); + is_of_type>); static_assert( - is_of_type>); + is_of_type>); static_assert( - is_of_type>); + is_of_type>); static_assert(is_of_type>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type>); static_assert(is_of_type, mean_sea_level, int>>); -static_assert(is_of_type>); +static_assert(is_of_type>); static_assert( is_of_type>); static_assert(is_of_type], mean_sea_level, int>>); static_assert(is_of_type<1 * m + mean_sea_level, quantity_point>); static_assert(is_of_type<1 * km + mean_sea_level, quantity_point, mean_sea_level, int>>); -static_assert(is_of_type>); +static_assert(is_of_type>); static_assert( is_of_type>); static_assert(is_of_type>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * m), quantity_point>); + is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * m), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * km), quantity_point>); + is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * km), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<(mean_sea_level + 1 * km) - isq::height(1 * m), quantity_point>); + is_of_type<(mean_sea_level + 1 * km) - isq::height(1 * m), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * m, quantity_point>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * m, quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * km, quantity_point>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * km, quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * km)) - 1 * m, quantity_point>); + is_of_type<(mean_sea_level + isq::height(1 * km)) - 1 * m, quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - isq::height(1 * m), - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - isq::height(1 * km), - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * km)) - isq::height(1 * m), - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type>); static_assert(is_of_type, mean_sea_level, int>>); @@ -1254,39 +1254,39 @@ static_assert(is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + 1 * m), q static_assert(is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + 1 * km), quantity>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * m)), quantity>); + is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * m)), quantity<(isq::height[m]), int>>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * km)), quantity>); + is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * km)), quantity<(isq::height[m]), int>>); static_assert( - is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + isq::height(1 * m)), quantity>); + is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + isq::height(1 * m)), quantity<(isq::height[m]), int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * m), quantity>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * km), quantity>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * km), quantity<(isq::height[m]), int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + 1 * m), quantity>); + is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + isq::height(1 * m)), - quantity>); + quantity<(isq::height[m]), int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + isq::height(1 * km)), - quantity>); + quantity<(isq::height[m]), int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + isq::height(1 * m)), - quantity>); + quantity<(isq::height[m]), int>>); static_assert(is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + 1 * m), quantity>); static_assert(is_of_type<(ground_level + 1 * m) - (ground_level + 1 * m), quantity>); static_assert(is_of_type<(tower_peak + 1 * m) - (tower_peak + 1 * m), quantity>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - (ground_level + 1 * m), quantity>); -static_assert(is_of_type<(ground_level + 1 * m) - (mean_sea_level + 1 * m), quantity>); -static_assert(is_of_type<(tower_peak + 1 * m) - (ground_level + 1 * m), quantity>); -static_assert(is_of_type<(ground_level + 1 * m) - (tower_peak + 1 * m), quantity>); -static_assert(is_of_type<(tower_peak + 1 * m) - (mean_sea_level + 1 * m), quantity>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - (tower_peak + 1 * m), quantity>); -static_assert(is_of_type<(other_ground_level + 1 * m) - (ground_level + 1 * m), quantity>); -static_assert(is_of_type<(ground_level + 1 * m) - (other_ground_level + 1 * m), quantity>); -static_assert(is_of_type<(other_ground_level + 1 * m) - (tower_peak + 1 * m), quantity>); -static_assert(is_of_type<(tower_peak + 1 * m) - (other_ground_level + 1 * m), quantity>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(ground_level + 1 * m) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(tower_peak + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(ground_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(tower_peak + 1 * m) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(other_ground_level + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(ground_level + 1 * m) - (other_ground_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(other_ground_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(tower_peak + 1 * m) - (other_ground_level + 1 * m), quantity<(isq::height[m]), int>>); static_assert(is_of_type>); static_assert(is_of_type, int>>); @@ -1298,32 +1298,32 @@ static_assert(is_of_type>); static_assert(is_of_type<(ground_level + 1 * km) - ground_level, quantity, int>>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type<(ground_level + 1 * m) - mean_sea_level, quantity>); -static_assert(is_of_type<(ground_level + 1 * km) - mean_sea_level, quantity>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type<(ground_level + 1 * m) - mean_sea_level, quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(ground_level + 1 * km) - mean_sea_level, quantity<(isq::height[m]), int>>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - ground_level, quantity>); -static_assert(is_of_type<(mean_sea_level + 1 * km) - ground_level, quantity>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - ground_level, quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(mean_sea_level + 1 * km) - ground_level, quantity<(isq::height[m]), int>>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); -static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + ground_level), quantity>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + mean_sea_level), quantity>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + ground_level), quantity>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + tower_peak), quantity>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + mean_sea_level), quantity>); -static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + tower_peak), quantity>); -static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + ground_level), quantity>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + other_ground_level), quantity>); -static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + tower_peak), quantity>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + other_ground_level), quantity>); +static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + mean_sea_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + mean_sea_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + other_ground_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + other_ground_level), quantity<(isq::height[m]), int>>); // check for integral types promotion diff --git a/test/static/quantity_test.cpp b/test/static/quantity_test.cpp index 7fcabec2..9d93cfe5 100644 --- a/test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -84,14 +84,14 @@ static_assert(std::is_nothrow_destructible_v>); static_assert(std::is_trivially_copyable_v>); static_assert(std::is_standard_layout_v>); -static_assert(std::default_initializable>); -static_assert(std::move_constructible>); -static_assert(std::copy_constructible>); -static_assert(std::equality_comparable>); -static_assert(std::totally_ordered>); -static_assert(std::regular>); +static_assert(std::default_initializable>); +static_assert(std::move_constructible>); +static_assert(std::copy_constructible>); +static_assert(std::equality_comparable>); +static_assert(std::totally_ordered>); +static_assert(std::regular>); -static_assert(std::three_way_comparable>); +static_assert(std::three_way_comparable>); ////////////////// @@ -112,8 +112,8 @@ static_assert(quantity::unit == si::metre); // member types ///////////////// -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::rep, int>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::rep, int>); //////////////////////////// @@ -135,11 +135,11 @@ static_assert(quantity::max().numerical_value_in(m) == s ///////////////////////////////////////////////// // construction from a value is private -static_assert(!std::constructible_from, double>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, double>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, int>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, int>); +static_assert(!std::convertible_to>); static_assert(std::constructible_from, double>); static_assert(std::convertible_to>); @@ -159,45 +159,45 @@ static_assert(std::convertible_to>); /////////////////////////////////////// // conversion only between convertible quantities -static_assert(std::constructible_from, quantity>); -static_assert(std::convertible_to, quantity>); -static_assert(std::constructible_from, quantity>); -static_assert(std::convertible_to, quantity>); -static_assert(std::constructible_from, quantity>); -static_assert(std::convertible_to, quantity>); +static_assert(std::constructible_from, quantity<(isq::length[m])>>); +static_assert(std::convertible_to, quantity<(isq::length[m])>>); +static_assert(std::constructible_from, quantity<(isq::distance[m])>>); +static_assert(std::convertible_to, quantity<(isq::length[m])>>); +static_assert(std::constructible_from, quantity<(isq::length[km])>>); +static_assert(std::convertible_to, quantity<(isq::length[m])>>); // conversion between different quantities not allowed -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity>); +static_assert(!std::constructible_from, quantity<(isq::time[s])>>); +static_assert(!std::convertible_to, quantity<(isq::length[m])>>); +static_assert(!std::constructible_from, quantity<(isq::speed[m / s])>>); +static_assert(!std::convertible_to, quantity<(isq::length[m])>>); // implicit conversion from another quantity only if non-truncating -static_assert(std::constructible_from, quantity>); // int -> double OK -static_assert(std::convertible_to, quantity>); // int -> double OK +static_assert(std::constructible_from, quantity<(isq::length[m]), int>>); // int -> double OK +static_assert(std::convertible_to, quantity<(isq::length[m])>>); // int -> double OK -static_assert(!std::constructible_from, - quantity>); // truncating double -> int not allowed -static_assert(!std::convertible_to, - quantity>); // truncating double -> int not allowed +static_assert(!std::constructible_from, + quantity<(isq::length[m])>>); // truncating double -> int not allowed +static_assert(!std::convertible_to, + quantity<(isq::length[m]), int>>); // truncating double -> int not allowed -static_assert(std::constructible_from, - quantity>); // kilometre -> metre OK -static_assert(std::convertible_to, - quantity>); // kilometre -> metre OK +static_assert(std::constructible_from, + quantity<(isq::length[km]), int>>); // kilometre -> metre OK +static_assert(std::convertible_to, + quantity<(isq::length[m]), int>>); // kilometre -> metre OK -static_assert(!std::constructible_from, - quantity>); // truncating metre -> +static_assert(!std::constructible_from, + quantity<(isq::length[m]), int>>); // truncating metre -> // kilometre not allowed static_assert( - !std::convertible_to, - quantity>); // truncating metre -> kilometre not allowed + !std::convertible_to, + quantity<(isq::length[km]), int>>); // truncating metre -> kilometre not allowed // converting to double always OK -static_assert(std::constructible_from, quantity>); -static_assert(std::convertible_to, quantity>); -static_assert(std::constructible_from, quantity>); -static_assert(std::convertible_to, quantity>); +static_assert(std::constructible_from, quantity<(isq::length[km]), int>>); +static_assert(std::convertible_to, quantity<(isq::length[m])>>); +static_assert(std::constructible_from, quantity<(isq::length[m]), int>>); +static_assert(std::convertible_to, quantity<(isq::length[km])>>); /////////////////////// // obtaining a number @@ -324,9 +324,9 @@ struct derived_quantity : quantity { // NOLINTEND(google-explicit-constructor, hicpp-explicit-conversions) }; -static_assert(Quantity, "NTTP type description">>); +static_assert(Quantity, "NTTP type description">>); -constexpr QuantityOf auto get_length_derived_quantity() noexcept +constexpr QuantityOf<(isq::length)> auto get_length_derived_quantity() noexcept { derived_quantity, "NTTP type description"> dist{}; dist += 1 * m; @@ -454,10 +454,10 @@ static_assert((std::uint8_t{255}* m %= 257 * m).numerical_value_in(m) != [] { #if !(defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 18 && defined MP_UNITS_MODULES) // next two lines trigger conversions warnings // (warning disabled in CMake for this file) -static_assert((22 * m *= 33.33).numerical_value_in(m) == 733); -static_assert((22 * m /= 3.33).numerical_value_in(m) == 6); -static_assert((22 * m *= 33.33 * one).numerical_value_in(m) == 733); -static_assert((22 * m /= 3.33 * one).numerical_value_in(m) == 6); +static_assert(((22 * m) *= 33.33).numerical_value_in(m) ==733); +static_assert(((22 * m) /= 3.33).numerical_value_in(m) == 6); +static_assert(((22 * m) *= 33.33 * one).numerical_value_in(m) == 733); +static_assert(((22 * m) /= 3.33 * one).numerical_value_in(m) == 6); #endif template typename Q> @@ -843,27 +843,27 @@ static_assert(2 * one / (1 * m) == 2 / (1 * m)); // equality operators /////////////////////// -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity<(si::metre)>>); +static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity<(si::metre)>>); +static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity<(si::metre)>>); +static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); +static_assert(std::equality_comparable_with, quantity<(si::kilo<(si::metre)>), int>>); +static_assert(std::equality_comparable_with, quantity<(isq::height[(si::metre)])>>); +static_assert(std::equality_comparable_with, quantity<(isq::height[(si::metre)]), int>>); static_assert( - std::equality_comparable_with, quantity], int>>); + std::equality_comparable_with, quantity<(isq::height[(si::kilo<(si::metre)>)]), int>>); template concept no_crossdimensional_equality = requires { requires !requires { 1 * s == 1 * M; }; requires !requires { 1 * s != 1 * M; }; }; -static_assert(no_crossdimensional_equality); +static_assert(no_crossdimensional_equality<(si::metre)>); // same type static_assert(123 * m == 123 * m); @@ -916,7 +916,7 @@ concept no_crossdimensional_ordering = requires { requires !requires { 1 * s <= 1 * M; }; requires !requires { 1 * s >= 1 * M; }; }; -static_assert(no_crossdimensional_ordering); +static_assert(no_crossdimensional_ordering<(si::metre)>); // same type static_assert(123 * m < 321 * m); @@ -1030,34 +1030,34 @@ static_assert(is_of_type(lvalue_q), quantity, isq::length>); -static_assert(QuantityOf, isq::length>); -static_assert(QuantityOf, isq::length>); -static_assert(!QuantityOf, isq::width>); -static_assert(QuantityOf, isq::width>); -static_assert(QuantityOf, isq::position_vector>); -static_assert(QuantityOf[m]>, isq::width>); -static_assert(QuantityOf[m]>, isq::position_vector>); -static_assert(!QuantityOf, isq::altitude>); +static_assert(QuantityOf, (isq::length)>); +static_assert(QuantityOf, (isq::length)>); +static_assert(QuantityOf, (isq::length)>); +static_assert(!QuantityOf, (isq::width)>); +static_assert(QuantityOf, (isq::width)>); +static_assert(QuantityOf, (isq::position_vector)>); +static_assert(QuantityOf[m]>, (isq::width)>); +static_assert(QuantityOf[m]>, (isq::position_vector)>); +static_assert(!QuantityOf, isq::altitude>); -static_assert(QuantityOf, isq::speed>); -static_assert(QuantityOf, isq::length / isq::time>); +static_assert(QuantityOf, (isq::speed)>); +static_assert(QuantityOf, (isq::length) / (isq::time)>); static_assert(QuantityOf, isq::length / isq::time>); -static_assert(QuantityOf[m / s]>, isq::length / isq::time>); -static_assert(!QuantityOf, isq::distance / isq::duration>); -static_assert(!QuantityOf, isq::width / isq::duration>); +static_assert(QuantityOf[m / s]>, (isq::length) / (isq::time)>); +static_assert(!QuantityOf, (isq::distance) / (isq::duration)>); +static_assert(!QuantityOf, (isq::width) / (isq::duration)>); static_assert(QuantityOf, isq::width / isq::duration>); -static_assert(QuantityOf[m / s]>, isq::width / isq::duration>); -static_assert(!QuantityOf, isq::position_vector / isq::duration>); +static_assert(QuantityOf[m / s]>, (isq::width) / (isq::duration)>); +static_assert(!QuantityOf, (isq::position_vector) / (isq::duration)>); static_assert(QuantityOf, isq::position_vector / isq::duration>); -static_assert(QuantityOf[m / s]>, isq::position_vector / isq::duration>); -static_assert(QuantityOf, isq::position_vector / isq::duration>); +static_assert(QuantityOf[m / s]>, isq::position_vector / isq::duration>); +static_assert(QuantityOf, isq::position_vector / isq::duration>); -static_assert(QuantityOf); // kind of -static_assert(QuantityOf[m]), isq::height>); // kind of -static_assert(!QuantityOf); // different kinds -static_assert(!QuantityOf); // different kinds -static_assert(QuantityOf); -static_assert(QuantityOf); // derived unnamed quantity +static_assert(QuantityOf); // kind of +static_assert(QuantityOf[m]), (isq::height)>); // kind of +static_assert(!QuantityOf); // different kinds +static_assert(!QuantityOf); // different kinds +static_assert(QuantityOf); +static_assert(QuantityOf); // derived unnamed quantity } // namespace diff --git a/test/static/reference_test.cpp b/test/static/reference_test.cpp index f7f3d709..46026702 100644 --- a/test/static/reference_test.cpp +++ b/test/static/reference_test.cpp @@ -238,7 +238,7 @@ template concept invalid_nu_unit = !requires { dim[unit]; }; static_assert(invalid_nu_unit); -static_assert(invalid_nu_unit); +static_assert(invalid_nu_unit<(nu::time), second>); static_assert(invalid_nu_unit); static_assert(invalid_nu_unit); static_assert(invalid_nu_unit); diff --git a/test/static/si_test.cpp b/test/static/si_test.cpp index 4f306fd2..d52a8edc 100644 --- a/test/static/si_test.cpp +++ b/test/static/si_test.cpp @@ -65,7 +65,7 @@ concept can_not_be_prefixed = Unit && !requires { typename prefix< static_assert(can_not_be_prefixed); static_assert(can_not_be_prefixed); -static_assert(can_not_be_prefixed>); +static_assert(can_not_be_prefixed)>); static_assert(can_not_be_prefixed); static_assert(can_not_be_prefixed * si::degree>); From d49175869745b9ee24f6cea3e84c967b6986d315 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:14:54 +0200 Subject: [PATCH 06/44] [msvc][fix] return type of chrono_literal "s" is not defined. Is double for msvc --- test/static/quantity_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/static/quantity_test.cpp b/test/static/quantity_test.cpp index 9d93cfe5..3beeea07 100644 --- a/test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -355,7 +355,8 @@ static_assert(quantity{123}.quantity_spec == kind_of); #if MP_UNITS_HOSTED using namespace std::chrono_literals; static_assert(std::is_same_v); -static_assert(std::is_same_v); +//return type for "s" is not specified. is double for msvc +//static_assert(std::is_same_v); static_assert(quantity{24h}.unit == si::hour); static_assert(quantity{24h}.quantity_spec == kind_of); #endif From e9ad43a71af71c55cf0c15ed08b1adbd4c09d069 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:18:27 +0200 Subject: [PATCH 07/44] [msvc][fix] CTAD for quantity_point does not work. --- example/currency.cpp | 14 ++++++------ test/static/quantity_point_test.cpp | 33 ++++++++++++++--------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/example/currency.cpp b/example/currency.cpp index 6f280659..0eb46040 100644 --- a/example/currency.cpp +++ b/example/currency.cpp @@ -90,11 +90,11 @@ template #endif -template auto To, ReferenceOf auto From, typename Rep> -quantity exchange_to(quantity q) -{ - return static_cast(exchange_rate() * q.numerical_value()) * To; -} +// template auto To, ReferenceOf auto From, typename Rep> +// quantity exchange_to(quantity q) +// { +// return static_cast(exchange_rate() * q.numerical_value()) * To; +// } template auto To, ReferenceOf auto From, auto PO, typename Rep> quantity_point exchange_to(quantity_point q) @@ -107,8 +107,8 @@ int main() { using namespace unit_symbols; - const quantity_point price_usd{100 * USD}; - const quantity_point price_euro = exchange_to(price_usd); + const mp_units::quantity_point price_usd{100 * USD}; + const mp_units::quantity_point price_euro = exchange_to(price_usd); std::cout << price_usd.quantity_from_zero() << " -> " << price_euro.quantity_from_zero() << "\n"; // std::cout << price_usd.quantity_from_zero() + price_euro.quantity_from_zero() << "\n"; // does diff --git a/test/static/quantity_point_test.cpp b/test/static/quantity_point_test.cpp index 64254d3e..5bfa7055 100644 --- a/test/static/quantity_point_test.cpp +++ b/test/static/quantity_point_test.cpp @@ -926,13 +926,12 @@ static_assert(quantity_point{sys_seconds{24h}}.quantity_spec == kind_of Date: Fri, 30 Aug 2024 13:19:35 +0200 Subject: [PATCH 08/44] [msvc][cmake] disable linear_algebra_test.cpp tests because of errors in mdspan --- test/runtime/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/runtime/CMakeLists.txt b/test/runtime/CMakeLists.txt index d79ed54b..70e13650 100644 --- a/test/runtime/CMakeLists.txt +++ b/test/runtime/CMakeLists.txt @@ -37,11 +37,11 @@ if(${projectPrefix}BUILD_CXX_MODULES) endif() target_link_libraries(unit_tests_runtime PRIVATE mp-units::mp-units Catch2::Catch2WithMain) -if(${projectPrefix}DEV_BUILD_LA) - find_package(wg21_linear_algebra REQUIRED) - target_sources(unit_tests_runtime PRIVATE linear_algebra_test.cpp) - target_link_libraries(unit_tests_runtime PRIVATE wg21_linear_algebra::wg21_linear_algebra) -endif() +# if(${projectPrefix}DEV_BUILD_LA) +# find_package(wg21_linear_algebra REQUIRED) +# target_sources(unit_tests_runtime PRIVATE linear_algebra_test.cpp) +# target_link_libraries(unit_tests_runtime PRIVATE wg21_linear_algebra::wg21_linear_algebra) +# endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options( From 482150eca1f868bf846c45c4bb804166d9e63efb Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:20:16 +0200 Subject: [PATCH 09/44] [msvc][fix] some more errros in examples --- example/total_energy.cpp | 14 +++++++------- example/unmanned_aerial_vehicle.cpp | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/example/total_energy.cpp b/example/total_energy.cpp index 95d23f31..f0b961b9 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -59,19 +59,19 @@ void si_example() const quantity c2 = pow<2>(c); const quantity p1 = isq::momentum(4. * GeV / c); - const QuantityOf auto m1 = 3. * GeV / c2; - const quantity E = total_energy(p1, m1, c); + const QuantityOf<(isq::mass)> auto m1 = 3. * GeV / c2; + const quantity E1 = total_energy(p1, m1, c); std::cout << "\n*** SI units (c = " << c << " = " << c.in(si::metre / s) << ") ***\n"; std::cout << "\n[in `GeV` and `c`]\n" << "p = " << p1 << "\n" << "m = " << m1 << "\n" - << "E = " << E << "\n"; + << "E = " << E1 << "\n"; const quantity p2 = p1.in(GeV / (m / s)); - const quantity m2 = m1.in(GeV / pow<2>(m / s)); - const quantity E2 = total_energy(p2, m2, c).in(GeV); + const quantity metre2 = m1.in(GeV / pow<2>(m / s)); + const quantity E2 = total_energy(p2, metre2, c).in(GeV); std::cout << "\n[in `GeV`]\n" << "p = " << p2 << "\n" @@ -79,8 +79,8 @@ void si_example() << "E = " << E2 << "\n"; const quantity p3 = p1.in(kg * m / s); - const quantity m3 = m1.in(kg); - const quantity E3 = total_energy(p3, m3, c).in(J); + const quantity metre3 = m1.in(kg); + const quantity E3 = total_energy(p3, metre3, c).in(J); std::cout << "\n[in SI base units]\n" << "p = " << p3 << "\n" diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index 3e26ac08..8a8648d5 100644 --- a/example/unmanned_aerial_vehicle.cpp +++ b/example/unmanned_aerial_vehicle.cpp @@ -70,6 +70,7 @@ constexpr const char* to_text(earth_gravity_model m) return "EGM2008-1"; } assert(false && "unsupported enum value"); + return "unsupported enum value"; } template From 19e358e56de7cb7455d2dee599e9d4b8a96e19f5 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:21:25 +0200 Subject: [PATCH 10/44] [mscv][fix] string_view iterator is not castalbe to char --- src/core/include/mp-units/format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/include/mp-units/format.h b/src/core/include/mp-units/format.h index 8cc5f25e..cc158e74 100644 --- a/src/core/include/mp-units/format.h +++ b/src/core/include/mp-units/format.h @@ -452,7 +452,7 @@ class MP_UNITS_STD_FMT::formatter, Char> { } // user provided format quantity_formatter f{*this, out, q, locale}; - parse_quantity_specs(modifiers_format_str_.begin(), modifiers_format_str_.end(), f); + parse_quantity_specs(modifiers_format_str_.data(), modifiers_format_str_.data() + modifiers_format_str_.size(), f); return f.out; } From 464c55538fb0d535d8fcbb4e43cc7e2b4e3f93c8 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:23:41 +0200 Subject: [PATCH 11/44] [msvc][fix] resolve ambigious call to find_first_of --- src/core/include/mp-units/format.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/include/mp-units/format.h b/src/core/include/mp-units/format.h index cc158e74..d5fea4b6 100644 --- a/src/core/include/mp-units/format.h +++ b/src/core/include/mp-units/format.h @@ -47,8 +47,8 @@ namespace mp_units::detail { template [[nodiscard]] constexpr const Char* at_most_one_of(const Char* begin, const Char* end, std::string_view modifiers) { - const Char* const it = find_first_of(begin, end, modifiers.begin(), modifiers.end()); - if (it != end && find_first_of(it + 1, end, modifiers.begin(), modifiers.end()) != end) + const Char* const it = mp_units::detail::find_first_of(begin, end, modifiers.begin(), modifiers.end()); + if (it != end && mp_units::detail::find_first_of(it + 1, end, modifiers.begin(), modifiers.end()) != end) throw MP_UNITS_STD_FMT::format_error("only one of '" + std::string(modifiers) + "' unit modifiers may be used in the format spec"); return it; From 5e657bac702a0d0e97a6d12f45e2c142dd75c9cc Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:26:38 +0200 Subject: [PATCH 12/44] [msvc][fix] msvc complains about requires expression (no common type found) replace with concept has_common_type --- src/core/include/mp-units/bits/sudo_cast.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/include/mp-units/bits/sudo_cast.h b/src/core/include/mp-units/bits/sudo_cast.h index fd7a9973..0db70246 100644 --- a/src/core/include/mp-units/bits/sudo_cast.h +++ b/src/core/include/mp-units/bits/sudo_cast.h @@ -30,11 +30,22 @@ namespace mp_units::detail { +template +struct has_common_type_impl : std::false_type {}; + +template +struct has_common_type_impl>, Ts...> : std::true_type {}; + +template +using has_common_type = typename has_common_type_impl::type; + +template constexpr bool has_common_type_v = has_common_type_impl::value; + template struct get_common_type : std::common_type {}; template -using maybe_common_type = MP_UNITS_TYPENAME std::conditional_t; }, +using maybe_common_type = MP_UNITS_TYPENAME std::conditional_t, get_common_type, std::type_identity>::type; /** From 3d32d5d833a9e0ece9d62aa205c817454a9ad117 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:27:37 +0200 Subject: [PATCH 13/44] [msvc][fix] internal compiler error for requires expression. "simplify" with extra concept --- src/core/include/mp-units/ostream.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/include/mp-units/ostream.h b/src/core/include/mp-units/ostream.h index e2464bd7..d9ba6e5d 100644 --- a/src/core/include/mp-units/ostream.h +++ b/src/core/include/mp-units/ostream.h @@ -89,9 +89,12 @@ std::basic_ostream& to_stream(std::basic_ostream& MP_UNITS_EXPORT_BEGIN +template +concept is_mp_units_stream = requires (OStream os, T v) { detail::to_stream_impl(os, v); }; + template std::basic_ostream& operator<<(std::basic_ostream& os, const T& v) - requires requires { detail::to_stream_impl(os, v); } + requires is_mp_units_stream, T> { return detail::to_stream(os, v); } From 924782f55775885cdc6a0ff424c5615db0763efd Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:32:55 +0200 Subject: [PATCH 14/44] [mscv][fix] weird problem with PO in quantity_point.h. replace with point_origin where needed --- .../include/mp-units/framework/quantity_point.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index aa4763d6..087fc7ab 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -191,13 +191,13 @@ public: [[nodiscard]] static constexpr quantity_point min() noexcept requires requires { quantity_type::min(); } { - return {quantity_type::min(), PO}; + return {quantity_type::min(), point_origin}; } [[nodiscard]] static constexpr quantity_point max() noexcept requires requires { quantity_type::max(); } { - return {quantity_type::max(), PO}; + return {quantity_type::max(), point_origin}; } // construction, assignment, destruction @@ -264,10 +264,10 @@ public: quantity_point& operator=(quantity_point&&) = default; template NewPO> - [[nodiscard]] constexpr MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(QuantityPointOf) auto point_for( + [[nodiscard]] constexpr QuantityPointOf<(NewPO{})> auto point_for( NewPO new_origin) const { - if constexpr (is_same_v) + if constexpr (is_same_v) return *this; else return ::mp_units::quantity_point{*this - new_origin, new_origin}; @@ -329,7 +329,7 @@ public: requires detail::QuantityConvertibleTo> [[nodiscard]] constexpr QuantityPointOf auto in(ToU) const { - return ::mp_units::quantity_point{quantity_ref_from(PO).in(ToU{}), PO}; + return ::mp_units::quantity_point{quantity_ref_from(point_origin).in(ToU{}), point_origin}; } template ToRep> @@ -350,7 +350,7 @@ public: requires requires(quantity_type q) { value_cast(q); } [[nodiscard]] constexpr QuantityPointOf auto force_in(ToU) const { - return ::mp_units::quantity_point{quantity_ref_from(PO).force_in(ToU{}), PO}; + return ::mp_units::quantity_point{quantity_ref_from(point_origin).force_in(ToU{}), PO}; } template ToRep> @@ -364,7 +364,7 @@ public: requires requires(quantity_type q) { value_cast(q); } [[nodiscard]] constexpr QuantityPointOf auto force_in(ToU) const { - return ::mp_units::quantity_point{quantity_ref_from(PO).template force_in(ToU{}), PO}; + return ::mp_units::quantity_point{quantity_ref_from(PO).template force_in(ToU{}), point_origin}; } // conversion operators From cea5d70dc0eb67a9d9bb6f4a5783523147edb4f2 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:33:16 +0200 Subject: [PATCH 15/44] [msvc][fix] disable C4702 unreachable code --- src/core/include/mp-units/bits/fmt.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/core/include/mp-units/bits/fmt.h b/src/core/include/mp-units/bits/fmt.h index c4572a9c..b12058b6 100644 --- a/src/core/include/mp-units/bits/fmt.h +++ b/src/core/include/mp-units/bits/fmt.h @@ -48,6 +48,12 @@ import std; #endif #endif + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4702) +#endif + // most of the below code is based on/copied from fmtlib namespace mp_units::detail { @@ -390,4 +396,9 @@ template } } // namespace mp_units::detail + +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + // NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-pro-type-union-access) From 3a6fc90c7be859fd11d234b5b30f16baa49fc747 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:36:12 +0200 Subject: [PATCH 16/44] [msvc][fix] compiler does not get that expression can be evalutated to a const. (caused by read of variable outside its lifetime) --- .../mp-units/framework/quantity_spec.h | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 94bce96a..9be678b9 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -1338,25 +1338,25 @@ template } template -[[nodiscard]] consteval specs_convertible_result convertible_kinds(From from_kind, To to_kind) +[[nodiscard]] consteval specs_convertible_result convertible_kinds(From, To) { constexpr auto exploded_kind_result = [](specs_convertible_result res) { using enum specs_convertible_result; return res == no ? no : yes; }; - if constexpr ((NamedQuantitySpec && NamedQuantitySpec) || - get_complexity(from_kind) == get_complexity(to_kind)) - return convertible_impl(from_kind, to_kind); - else if constexpr (get_complexity(from_kind) > get_complexity(to_kind)) + if constexpr ((NamedQuantitySpec && NamedQuantitySpec) || + get_complexity(From{}) == get_complexity(To{})) + return convertible_impl(From{}, To{}); + else if constexpr (get_complexity(From{}) > get_complexity(To{})) return exploded_kind_result( - convertible_impl(get_kind_tree_root(explode(from_kind).quantity), to_kind)); + convertible_impl(get_kind_tree_root(explode(From{}).quantity), To{})); else return exploded_kind_result( - convertible_impl(from_kind, get_kind_tree_root(explode(to_kind).quantity))); + convertible_impl(From{}, get_kind_tree_root(explode(To{}).quantity))); } template -[[nodiscard]] consteval specs_convertible_result convertible_named(From from, To to) +[[nodiscard]] consteval specs_convertible_result convertible_named(From, To) { using enum specs_convertible_result; @@ -1369,16 +1369,16 @@ template return no; else if constexpr (get_complexity(From{}) != get_complexity(To{})) { if constexpr (get_complexity(From{}) > get_complexity(To{})) - return convertible_impl(explode(from).quantity, to); + return convertible_impl(explode(From{}).quantity, To{}); else { - auto res = explode(to); - return min(res.result, convertible_impl(from, res.quantity)); + auto res = explode(To{}); + return min(res.result, convertible_impl(From{}, res.quantity)); } } } template -[[nodiscard]] consteval specs_convertible_result convertible_impl(From from, To to) +[[nodiscard]] consteval specs_convertible_result convertible_impl(From, To) { using enum specs_convertible_result; @@ -1388,30 +1388,30 @@ template else if constexpr (From::dimension != To::dimension) return no; else if constexpr (QuantityKindSpec || QuantityKindSpec) - return convertible_kinds(get_kind_tree_root(from), get_kind_tree_root(to)); - else if constexpr (NestedQuantityKindSpecOf && get_kind_tree_root(To{}) == To{}) + return convertible_kinds(get_kind_tree_root(From{}), get_kind_tree_root(To{})); + else if constexpr (NestedQuantityKindSpecOf && get_kind_tree_root(To{}) == To{}) return yes; - else if constexpr (NamedQuantitySpec && NamedQuantitySpec) - return convertible_named(from, to); - else if constexpr (DerivedQuantitySpec && DerivedQuantitySpec) - return are_ingredients_convertible(from, to); - else if constexpr (DerivedQuantitySpec) { - auto res = explode(from); + else if constexpr (NamedQuantitySpec && NamedQuantitySpec) { + return convertible_named(From{}, To{}); + } else if constexpr (DerivedQuantitySpec && DerivedQuantitySpec) { + return are_ingredients_convertible(From{}, To{}); + } else if constexpr (DerivedQuantitySpec) { + auto res = explode(From{}); if constexpr (NamedQuantitySpec) - return convertible_impl(res.quantity, to); - else if constexpr (requires { to._equation_; }) { - auto eq = explode_to_equation(to); + return convertible_impl(res.quantity, To{}); + else if constexpr (requires { To{}._equation_; }) { + auto eq = explode_to_equation(To{}); return min(eq.result, convertible_impl(res.quantity, eq.equation)); } else - return are_ingredients_convertible(from, to); + return are_ingredients_convertible(From{}, To{}); } else if constexpr (DerivedQuantitySpec) { - auto res = explode(to); + auto res = explode(To{}); if constexpr (NamedQuantitySpec) - return min(res.result, convertible_impl(from, res.quantity)); - else if constexpr (requires { from._equation_; }) - return min(res.result, convertible_impl(from._equation_, res.quantity)); + return min(res.result, convertible_impl(From{}, res.quantity)); + else if constexpr (requires { From{}._equation_; }) + return min(res.result, convertible_impl(From{}._equation_, res.quantity)); else - return min(res.result, are_ingredients_convertible(from, to)); + return min(res.result, are_ingredients_convertible(From{}, To{})); } // NOLINTEND(bugprone-branch-clone) return no; @@ -1496,9 +1496,9 @@ template MP_UNITS_EXPORT_BEGIN template -[[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q q) +[[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q) { - return kind_of; + return kind_of; } [[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q) { return q; } From 918a8b7e8f1b79a5d4936ac95087a14356fbbaa8 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:37:51 +0200 Subject: [PATCH 17/44] [msvc][fix] parse error in refernce.h. resolved with more brackets. --- src/core/include/mp-units/framework/reference.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index c6424e1f..9bb6b15d 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -87,37 +87,40 @@ struct reference { } template - [[nodiscard]] friend consteval detail::reference_t operator*(reference, reference) + [[nodiscard]] friend consteval detail::reference_t<(Q{} * Q2{}), (U{} * U2{})> operator*(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t operator*(reference, U2) + [[nodiscard]] friend consteval detail::reference_t<((Q{} * get_quantity_spec(U2{}))), (U{} * U2{})> operator*(reference, + U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t operator*(U1, reference) + [[nodiscard]] friend consteval detail::reference_t<(get_quantity_spec(U1{}) * Q{}), (U1{} * U{})> operator*(U1, + reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t operator/(reference, reference) + [[nodiscard]] friend consteval detail::reference_t<(Q{} / Q2{}), (U{} / U2{})> operator/(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t operator/(reference, U2) + [[nodiscard]] friend consteval detail::reference_t<(Q{} / get_quantity_spec(U2{})), (U{} / U2{})> operator/(reference, + U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t operator/(U1, reference) + [[nodiscard]] friend consteval detail::reference_t<(get_quantity_spec(U1{}) / Q{}), (U1{} / U{})> operator/(U1, reference) { return {}; } From 4b61716bb4bfd05b83440d54ea85eab57e29e283 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:42:28 +0200 Subject: [PATCH 18/44] :boom: [msvc][conan] enable msvc with version 194. --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index 3a8fd5f5..5a876a11 100644 --- a/conanfile.py +++ b/conanfile.py @@ -94,7 +94,7 @@ class MPUnitsConan(ConanFile): "gcc": "12", "clang": "16", "apple-clang": "15", - "msvc": "", + "msvc": "194", }, }, "std_format": { From 4d715734bf3e120c0628d06a432829df003cc7ca Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:27:44 +0200 Subject: [PATCH 19/44] [msvc][fix] update changes for master --- .../mp-units/bits/get_associated_quantity.h | 4 +-- .../mp-units/framework/construction_helpers.h | 4 +-- .../include/mp-units/framework/magnitude.h | 2 +- .../mp-units/framework/quantity_point.h | 14 +++++------ .../mp-units/framework/quantity_spec.h | 8 +++--- .../include/mp-units/framework/reference.h | 4 +-- src/core/include/mp-units/framework/unit.h | 2 +- test/static/chrono_test.cpp | 12 ++++----- test/static/concepts_test.cpp | 25 ------------------- test/static/quantity_point_test.cpp | 10 ++++---- test/static/quantity_test.cpp | 12 ++++----- 11 files changed, 36 insertions(+), 61 deletions(-) diff --git a/src/core/include/mp-units/bits/get_associated_quantity.h b/src/core/include/mp-units/bits/get_associated_quantity.h index 881c61e8..d976b17e 100644 --- a/src/core/include/mp-units/bits/get_associated_quantity.h +++ b/src/core/include/mp-units/bits/get_associated_quantity.h @@ -76,9 +76,9 @@ template template [[nodiscard]] consteval auto get_associated_quantity(U u) { - constexpr bool all_kinds = all_are_kinds(u); + constexpr bool all_kinds = all_are_kinds(U{}); if constexpr (all_kinds) - return kind_of; + return kind_of; else return get_associated_quantity_impl(u); } diff --git a/src/core/include/mp-units/framework/construction_helpers.h b/src/core/include/mp-units/framework/construction_helpers.h index 6e20ebcc..c0226e47 100644 --- a/src/core/include/mp-units/framework/construction_helpers.h +++ b/src/core/include/mp-units/framework/construction_helpers.h @@ -41,7 +41,7 @@ template struct delta_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity> operator()(Rep&& lhs) const + [[nodiscard]] constexpr quantity<(R{}), std::remove_cvref_t> operator()(Rep&& lhs) const { return quantity{std::forward(lhs), R{}}; } @@ -51,7 +51,7 @@ template struct absolute_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity_point> operator()( + [[nodiscard]] constexpr quantity_point<(R{}), default_point_origin(R{}), std::remove_cvref_t> operator()( Rep&& lhs) const { return quantity_point{quantity{std::forward(lhs), R{}}}; diff --git a/src/core/include/mp-units/framework/magnitude.h b/src/core/include/mp-units/framework/magnitude.h index d1632528..9c088c78 100644 --- a/src/core/include/mp-units/framework/magnitude.h +++ b/src/core/include/mp-units/framework/magnitude.h @@ -708,7 +708,7 @@ void to_base_specialization_of_magnitude(const volatile magnitude*); template inline constexpr bool is_derived_from_specialization_of_magnitude = - requires(T* t) { to_base_specialization_of_magnitude(t); }; + requires(T* type) { to_base_specialization_of_magnitude(type); }; template requires is_derived_from_specialization_of_magnitude diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index 087fc7ab..5b449ea8 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -54,14 +54,14 @@ template struct point_origin_interface { template requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+(PO, Q&& q) + [[nodiscard]] friend constexpr quantity_point operator+(PO, Q&& q) { return quantity_point{std::forward(q), PO{}}; } template requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+(Q&& q, PO po) + [[nodiscard]] friend constexpr quantity_point operator+(Q&& q, PO po) { return po + std::forward(q); } @@ -336,35 +336,35 @@ public: requires detail::QuantityConvertibleTo> [[nodiscard]] constexpr QuantityPointOf auto in() const { - return ::mp_units::quantity_point{quantity_ref_from(PO).template in(), PO}; + return ::mp_units::quantity_point{quantity_ref_from(point_origin).template in(), point_origin}; } template ToRep, detail::UnitCompatibleWith ToU> requires detail::QuantityConvertibleTo> [[nodiscard]] constexpr QuantityPointOf auto in(ToU) const { - return ::mp_units::quantity_point{quantity_ref_from(PO).template in(ToU{}), PO}; + return ::mp_units::quantity_point{quantity_ref_from(point_origin).template in(ToU{}), point_origin}; } template ToU> requires requires(quantity_type q) { value_cast(q); } [[nodiscard]] constexpr QuantityPointOf auto force_in(ToU) const { - return ::mp_units::quantity_point{quantity_ref_from(point_origin).force_in(ToU{}), PO}; + return ::mp_units::quantity_point{quantity_ref_from(point_origin).force_in(ToU{}), point_origin}; } template ToRep> requires requires(quantity_type q) { value_cast(q); } [[nodiscard]] constexpr QuantityPointOf auto force_in() const { - return ::mp_units::quantity_point{quantity_ref_from(PO).template force_in(), PO}; + return ::mp_units::quantity_point{quantity_ref_from(point_origin).template force_in(), point_origin}; } template ToRep, detail::UnitCompatibleWith ToU> requires requires(quantity_type q) { value_cast(q); } [[nodiscard]] constexpr QuantityPointOf auto force_in(ToU) const { - return ::mp_units::quantity_point{quantity_ref_from(PO).template force_in(ToU{}), point_origin}; + return ::mp_units::quantity_point{quantity_ref_from(point_origin).template force_in(ToU{}), point_origin}; } // conversion operators diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 9be678b9..51b497e0 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -673,9 +673,9 @@ template template [[nodiscard]] consteval bool ingredients_dimension_less(D1 lhs, D2 rhs) { - if constexpr (lhs == rhs || lhs == dimension_one) + if constexpr (D1{} == D2{} || D1{} == dimension_one) return false; - else if constexpr (rhs == dimension_one) + else if constexpr (D2{} == dimension_one) return true; else return detail::type_name() < detail::type_name(); @@ -1496,9 +1496,9 @@ template MP_UNITS_EXPORT_BEGIN template -[[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q) +[[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q q) { - return kind_of; + return kind_of; } [[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q) { return q; } diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index 9bb6b15d..35f646ee 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -288,9 +288,9 @@ template } -> Unit; } { - return detail::reference_t{}; + common_unit(get_unit(R1{}), get_unit(R2{}), get_unit(rest)...)>{}; } MP_UNITS_EXPORT_END diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index f6a52e4f..b00d4792 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -633,7 +633,7 @@ template template [[nodiscard]] consteval Unit auto common_unit(U1 u1, U2 u2) - requires(convertible(u1, u2)) + requires(convertible(U1{}, U2{})) { if constexpr (is_same_v) return u1; diff --git a/test/static/chrono_test.cpp b/test/static/chrono_test.cpp index a3a0d489..c4b03cd9 100644 --- a/test/static/chrono_test.cpp +++ b/test/static/chrono_test.cpp @@ -107,13 +107,13 @@ static_assert(is_of_type>); -static_assert(std::convertible_to, std::chrono::seconds>); -static_assert(std::constructible_from>); -static_assert(std::convertible_to, std::chrono::hours>); + std::constructible_from>); +static_assert(std::convertible_to, std::chrono::seconds>); +static_assert(std::constructible_from>); +static_assert(std::convertible_to, std::chrono::hours>); static_assert( - std::constructible_from>); -static_assert(std::convertible_to, sys_seconds>); + std::constructible_from>); +static_assert(std::convertible_to, sys_seconds>); // units mapping static_assert(quantity{1ns} == 1 * ns); diff --git a/test/static/concepts_test.cpp b/test/static/concepts_test.cpp index a419d8d4..52a1f96a 100644 --- a/test/static/concepts_test.cpp +++ b/test/static/concepts_test.cpp @@ -155,31 +155,6 @@ static_assert(!Unit); static_assert(!Unit); #endif -// NamedUnit -static_assert(detail::NamedUnit); -static_assert(detail::NamedUnit); -static_assert(!detail::NamedUnit); -static_assert(!detail::NamedUnit))>); -static_assert(!detail::NamedUnit); -static_assert(!detail::NamedUnit); -static_assert(!detail::NamedUnit * si::second)>); -static_assert(!detail::NamedUnit); -static_assert(!detail::NamedUnit(si::metre))>); -static_assert(detail::NamedUnit); -static_assert(!detail::NamedUnit, struct si::second>>); -static_assert(!detail::NamedUnit>>); -static_assert(!detail::NamedUnit); -static_assert(!detail::NamedUnit>>); -static_assert(!detail::NamedUnit>); -static_assert(!detail::NamedUnit>); -static_assert(!detail::NamedUnit>>); -static_assert(!detail::NamedUnit, (si::second)>>); -static_assert(!detail::NamedUnit); -static_assert(!detail::NamedUnit); -#if MP_UNITS_HOSTED -static_assert(!detail::NamedUnit); -#endif - // PrefixableUnit static_assert(PrefixableUnit); static_assert(PrefixableUnit); diff --git a/test/static/quantity_point_test.cpp b/test/static/quantity_point_test.cpp index 5bfa7055..fafbcb65 100644 --- a/test/static/quantity_point_test.cpp +++ b/test/static/quantity_point_test.cpp @@ -1131,12 +1131,12 @@ concept invalid_binary_operations = requires { requires !requires { Origin - Origin; }; // unit constants - requires !requires { QP(1) + m; }; - requires !requires { QP(1) - m; }; + requires !requires { QP<(si::metre), mean_sea_level, int>(1) + m; }; + requires !requires { QP<(si::metre), mean_sea_level, int>(1) - m; }; requires !requires { Origin + m; }; requires !requires { Origin - m; }; - requires !requires { m + QP(1); }; - requires !requires { m - QP(1); }; + requires !requires { m + QP<(si::metre), mean_sea_level, int>(1); }; + requires !requires { m - QP<(si::metre), mean_sea_level, int>(1); }; requires !requires { m + Origin; }; requires !requires { m - Origin; }; }; @@ -1717,7 +1717,7 @@ static_assert(value_cast(quantity_point{2 * km}).quantity_from_zero().numeric static_assert(value_cast(quantity_point{2000 * m}).quantity_from_zero().numerical_value_in(km) == 2); static_assert(value_cast(quantity_point{1.23 * m}).quantity_from_zero().numerical_value_in(m) == 1); static_assert( - value_cast(quantity_point{2000.0 * m / (3600.0 * s)}).quantity_from_zero().numerical_value_in(km / h) == 2); + value_cast<(km / h)>(quantity_point{2000.0 * m / (3600.0 * s)}).quantity_from_zero().numerical_value_in(km / h) == 2); // lvalue references in value_cast namespace lvalue_tests { constexpr quantity_point lvalue_qp{2 * km}; diff --git a/test/static/quantity_test.cpp b/test/static/quantity_test.cpp index 3beeea07..6cd56773 100644 --- a/test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -215,16 +215,16 @@ static_assert(quantity(1500 * m).numerical_value_in(km) == 1.5) static_assert(!std::convertible_to, double>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, double>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, double>); +static_assert(std::constructible_from>); static_assert(!std::convertible_to, int>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, int>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, int>); +static_assert(std::constructible_from>); static_assert(!std::convertible_to, double>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, double>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, double>); +static_assert(std::constructible_from>); /////////////////////////////////// From e258009a6a5cd7e4b1fe640b9b58bc27f9f6e7b7 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:27:53 +0200 Subject: [PATCH 20/44] [msvc][fmt] diable warning in smalest scope --- src/core/include/mp-units/bits/fmt.h | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/core/include/mp-units/bits/fmt.h b/src/core/include/mp-units/bits/fmt.h index b12058b6..1505ce25 100644 --- a/src/core/include/mp-units/bits/fmt.h +++ b/src/core/include/mp-units/bits/fmt.h @@ -48,12 +48,6 @@ import std; #endif #endif - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4702) -#endif - // most of the below code is based on/copied from fmtlib namespace mp_units::detail { @@ -195,6 +189,10 @@ constexpr void handle_dynamic_spec(int& value, fmt_arg_ref [[nodiscard]] constexpr unsigned long long operator()(T value) const @@ -204,11 +202,14 @@ struct width_checker { if (value < 0) MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("negative width")); return static_cast(value); } - MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("width is not integer")); - return 0; + MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("width is not integer")); } }; +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + MP_UNITS_EXPORT_END // Parses the range [begin, end) as an unsigned integer. This function assumes @@ -259,7 +260,6 @@ template if (c == '%') return begin; // mp-units extension if (!::mp_units::detail::is_name_start(c)) { MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid format string")); - return begin; } auto it = begin; do { @@ -378,7 +378,6 @@ template if (c == '}') return begin; if (c == '{') { MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("invalid fill character '{'")); - return begin; } specs.fill = {begin, to_unsigned(p - begin)}; begin = p + 1; @@ -396,9 +395,4 @@ template } } // namespace mp_units::detail - -#ifdef _MSC_VER -#pragma warning( pop ) -#endif - // NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-pro-type-union-access) From 5ae1304eee38ed2c05a858732b2e7779703d8d23 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:07:08 +0200 Subject: [PATCH 21/44] [hacks] add MP_UNITS_EXPRESSION --- src/core/include/mp-units/bits/hacks.h | 2 ++ src/core/include/mp-units/framework/quantity_point.h | 8 ++++---- src/core/include/mp-units/framework/reference.h | 12 ++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 5030debb..905aea8f 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -80,10 +80,12 @@ #if MP_UNITS_COMP_MSVC #define MP_UNITS_TYPENAME typename +#define MP_UNITS_EXPRESSION(x) (x) #else #define MP_UNITS_TYPENAME +#define MP_UNITS_EXPRESSION(x) x #endif diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index 5b449ea8..58b28b3f 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -54,14 +54,14 @@ template struct point_origin_interface { template requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+(PO, Q&& q) + [[nodiscard]] friend constexpr quantity_point operator+(PO, Q&& q) { return quantity_point{std::forward(q), PO{}}; } template requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+(Q&& q, PO po) + [[nodiscard]] friend constexpr quantity_point operator+(Q&& q, PO po) { return po + std::forward(q); } @@ -191,13 +191,13 @@ public: [[nodiscard]] static constexpr quantity_point min() noexcept requires requires { quantity_type::min(); } { - return {quantity_type::min(), point_origin}; + return {quantity_type::min(), PO}; } [[nodiscard]] static constexpr quantity_point max() noexcept requires requires { quantity_type::max(); } { - return {quantity_type::max(), point_origin}; + return {quantity_type::max(), PO}; } // construction, assignment, destruction diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index 35f646ee..a0452b51 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -87,40 +87,40 @@ struct reference { } template - [[nodiscard]] friend consteval detail::reference_t<(Q{} * Q2{}), (U{} * U2{})> operator*(reference, reference) + [[nodiscard]] friend consteval detail::reference_t operator*(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t<((Q{} * get_quantity_spec(U2{}))), (U{} * U2{})> operator*(reference, + [[nodiscard]] friend consteval detail::reference_t<(MP_UNITS_EXPRESSION(Q{} * get_quantity_spec(U2{}))), MP_UNITS_EXPRESSION(U{} * U2{})> operator*(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t<(get_quantity_spec(U1{}) * Q{}), (U1{} * U{})> operator*(U1, + [[nodiscard]] friend consteval detail::reference_t operator*(U1, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t<(Q{} / Q2{}), (U{} / U2{})> operator/(reference, reference) + [[nodiscard]] friend consteval detail::reference_t operator/(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t<(Q{} / get_quantity_spec(U2{})), (U{} / U2{})> operator/(reference, + [[nodiscard]] friend consteval detail::reference_t operator/(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t<(get_quantity_spec(U1{}) / Q{}), (U1{} / U{})> operator/(U1, reference) + [[nodiscard]] friend consteval detail::reference_t operator/(U1, reference) { return {}; } From a89bfc6c2154cac17116fe548b107d569c90be14 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:14:42 +0200 Subject: [PATCH 22/44] [hacks] add MP_UNITS_IS_VALUE --- src/core/include/mp-units/bits/hacks.h | 2 ++ .../mp-units/framework/construction_helpers.h | 4 ++-- src/systems/include/mp-units/systems/si/chrono.h | 4 ++-- src/systems/include/mp-units/systems/si/math.h | 14 +++++++------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 905aea8f..bbd3eec7 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -81,11 +81,13 @@ #define MP_UNITS_TYPENAME typename #define MP_UNITS_EXPRESSION(x) (x) +#define MP_UNITS_IS_VALUE(x) (x) #else #define MP_UNITS_TYPENAME #define MP_UNITS_EXPRESSION(x) x +#define MP_UNITS_IS_VALUE(x) #endif diff --git a/src/core/include/mp-units/framework/construction_helpers.h b/src/core/include/mp-units/framework/construction_helpers.h index c0226e47..43e44c81 100644 --- a/src/core/include/mp-units/framework/construction_helpers.h +++ b/src/core/include/mp-units/framework/construction_helpers.h @@ -41,7 +41,7 @@ template struct delta_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity<(R{}), std::remove_cvref_t> operator()(Rep&& lhs) const + [[nodiscard]] constexpr quantity> operator()(Rep&& lhs) const { return quantity{std::forward(lhs), R{}}; } @@ -51,7 +51,7 @@ template struct absolute_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity_point<(R{}), default_point_origin(R{}), std::remove_cvref_t> operator()( + [[nodiscard]] constexpr quantity_point> operator()( Rep&& lhs) const { return quantity_point{quantity{std::forward(lhs), R{}}}; diff --git a/src/systems/include/mp-units/systems/si/chrono.h b/src/systems/include/mp-units/systems/si/chrono.h index 0fad31e1..c018e8d1 100644 --- a/src/systems/include/mp-units/systems/si/chrono.h +++ b/src/systems/include/mp-units/systems/si/chrono.h @@ -127,13 +127,13 @@ namespace detail { } // namespace detail -template Q> +template Q> [[nodiscard]] constexpr auto to_chrono_duration(const Q& q) { return std::chrono::duration{q}; } -template QP> +template QP> requires is_specialization_of, chrono_point_origin_> [[nodiscard]] constexpr auto to_chrono_time_point(const QP& qp) { diff --git a/src/systems/include/mp-units/systems/si/math.h b/src/systems/include/mp-units/systems/si/math.h index 202ea76d..0a863585 100644 --- a/src/systems/include/mp-units/systems/si/math.h +++ b/src/systems/include/mp-units/systems/si/math.h @@ -43,7 +43,7 @@ import std; MP_UNITS_EXPORT namespace mp_units::si { -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { sin(v); } || requires(Rep v) { std::sin(v); } [[nodiscard]] inline QuantityOf auto sin(const quantity& q) noexcept { @@ -57,7 +57,7 @@ template auto R, typename Rep> return quantity{sin(q.numerical_value_in(radian)), one}; } -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { cos(v); } || requires(Rep v) { std::cos(v); } [[nodiscard]] inline QuantityOf auto cos(const quantity& q) noexcept { @@ -71,7 +71,7 @@ template auto R, typename Rep> return quantity{cos(q.numerical_value_in(radian)), one}; } -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { tan(v); } || requires(Rep v) { std::tan(v); } [[nodiscard]] inline QuantityOf auto tan(const quantity& q) noexcept { @@ -87,7 +87,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { asin(v); } || requires(Rep v) { std::asin(v); } -[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto asin(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto asin(const quantity& q) noexcept { using std::asin; if constexpr (!treat_as_floating_point) { @@ -101,7 +101,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { acos(v); } || requires(Rep v) { std::acos(v); } -[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto acos(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto acos(const quantity& q) noexcept { using std::acos; if constexpr (!treat_as_floating_point) { @@ -115,7 +115,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { atan(v); } || requires(Rep v) { std::atan(v); } -[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto atan(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto atan(const quantity& q) noexcept { using std::atan; if constexpr (!treat_as_floating_point) { @@ -132,7 +132,7 @@ template common_reference(R1, R2); requires requires { atan2(v1, v2); } || requires { std::atan2(v1, v2); }; } -[[nodiscard]] inline QuantityOf<(isq::angular_measure)> auto atan2(const quantity& y, +[[nodiscard]] inline QuantityOf auto atan2(const quantity& y, const quantity& x) noexcept { constexpr auto ref = common_reference(R1, R2); From 48c4f297c80f47261f90f212f5f4533941acb2b2 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:27:57 +0200 Subject: [PATCH 23/44] [hacks] add MP_UNITS_IS_CONST_EXPR(from) --- .../mp-units/bits/get_associated_quantity.h | 4 +- src/core/include/mp-units/bits/hacks.h | 4 +- .../mp-units/framework/quantity_spec.h | 64 +++++++++---------- .../include/mp-units/framework/reference.h | 4 +- src/core/include/mp-units/framework/unit.h | 2 +- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/core/include/mp-units/bits/get_associated_quantity.h b/src/core/include/mp-units/bits/get_associated_quantity.h index d976b17e..1339ca0f 100644 --- a/src/core/include/mp-units/bits/get_associated_quantity.h +++ b/src/core/include/mp-units/bits/get_associated_quantity.h @@ -76,9 +76,9 @@ template template [[nodiscard]] consteval auto get_associated_quantity(U u) { - constexpr bool all_kinds = all_are_kinds(U{}); + constexpr bool all_kinds = all_are_kinds(MP_UNITS_IS_CONST_EXPR(u)); if constexpr (all_kinds) - return kind_of; + return kind_of; else return get_associated_quantity_impl(u); } diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index bbd3eec7..09a6daab 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -82,12 +82,14 @@ #define MP_UNITS_TYPENAME typename #define MP_UNITS_EXPRESSION(x) (x) #define MP_UNITS_IS_VALUE(x) (x) +#define MP_UNITS_IS_CONST_EXPR(x) decltype(x){} #else #define MP_UNITS_TYPENAME #define MP_UNITS_EXPRESSION(x) x -#define MP_UNITS_IS_VALUE(x) +#define MP_UNITS_IS_VALUE(x) x +#define MP_UNITS_IS_CONST_EXPR(x) x #endif diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 51b497e0..af23ad74 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -673,9 +673,9 @@ template template [[nodiscard]] consteval bool ingredients_dimension_less(D1 lhs, D2 rhs) { - if constexpr (D1{} == D2{} || D1{} == dimension_one) + if constexpr (MP_UNITS_IS_CONST_EXPR(lhs) == MP_UNITS_IS_CONST_EXPR(rhs) || MP_UNITS_IS_CONST_EXPR(lhs) == dimension_one) return false; - else if constexpr (D2{} == dimension_one) + else if constexpr (MP_UNITS_IS_CONST_EXPR(rhs) == dimension_one) return true; else return detail::type_name() < detail::type_name(); @@ -1338,25 +1338,25 @@ template } template -[[nodiscard]] consteval specs_convertible_result convertible_kinds(From, To) +[[nodiscard]] consteval specs_convertible_result convertible_kinds(From from_kind, To to_kind) { constexpr auto exploded_kind_result = [](specs_convertible_result res) { using enum specs_convertible_result; return res == no ? no : yes; }; - if constexpr ((NamedQuantitySpec && NamedQuantitySpec) || - get_complexity(From{}) == get_complexity(To{})) - return convertible_impl(From{}, To{}); - else if constexpr (get_complexity(From{}) > get_complexity(To{})) + if constexpr ((NamedQuantitySpec && NamedQuantitySpec) || + get_complexity(MP_UNITS_IS_CONST_EXPR(from_kind)) == get_complexity(MP_UNITS_IS_CONST_EXPR(to_kind))) + return convertible_impl(MP_UNITS_IS_CONST_EXPR(from_kind), MP_UNITS_IS_CONST_EXPR(to_kind)); + else if constexpr (get_complexity(MP_UNITS_IS_CONST_EXPR(from_kind)) > get_complexity(MP_UNITS_IS_CONST_EXPR(to_kind))) return exploded_kind_result( - convertible_impl(get_kind_tree_root(explode(From{}).quantity), To{})); + convertible_impl(get_kind_tree_root(explode(MP_UNITS_IS_CONST_EXPR(from_kind)).quantity), MP_UNITS_IS_CONST_EXPR(to_kind))); else return exploded_kind_result( - convertible_impl(From{}, get_kind_tree_root(explode(To{}).quantity))); + convertible_impl(MP_UNITS_IS_CONST_EXPR(from_kind), get_kind_tree_root(explode(MP_UNITS_IS_CONST_EXPR(to_kind)).quantity))); } template -[[nodiscard]] consteval specs_convertible_result convertible_named(From, To) +[[nodiscard]] consteval specs_convertible_result convertible_named(From from, To to) { using enum specs_convertible_result; @@ -1369,16 +1369,16 @@ template return no; else if constexpr (get_complexity(From{}) != get_complexity(To{})) { if constexpr (get_complexity(From{}) > get_complexity(To{})) - return convertible_impl(explode(From{}).quantity, To{}); + return convertible_impl(explode(MP_UNITS_IS_CONST_EXPR(from)).quantity, MP_UNITS_IS_CONST_EXPR(to)); else { - auto res = explode(To{}); - return min(res.result, convertible_impl(From{}, res.quantity)); + auto res = explode(MP_UNITS_IS_CONST_EXPR(to)); + return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR(from), res.quantity)); } } } template -[[nodiscard]] consteval specs_convertible_result convertible_impl(From, To) +[[nodiscard]] consteval specs_convertible_result convertible_impl(From from, To to) { using enum specs_convertible_result; @@ -1388,30 +1388,30 @@ template else if constexpr (From::dimension != To::dimension) return no; else if constexpr (QuantityKindSpec || QuantityKindSpec) - return convertible_kinds(get_kind_tree_root(From{}), get_kind_tree_root(To{})); - else if constexpr (NestedQuantityKindSpecOf && get_kind_tree_root(To{}) == To{}) + return convertible_kinds(get_kind_tree_root(MP_UNITS_IS_CONST_EXPR(from)), get_kind_tree_root(MP_UNITS_IS_CONST_EXPR(to))); + else if constexpr (NestedQuantityKindSpecOf && get_kind_tree_root(To{}) == To{}) return yes; - else if constexpr (NamedQuantitySpec && NamedQuantitySpec) { - return convertible_named(From{}, To{}); - } else if constexpr (DerivedQuantitySpec && DerivedQuantitySpec) { - return are_ingredients_convertible(From{}, To{}); - } else if constexpr (DerivedQuantitySpec) { - auto res = explode(From{}); + else if constexpr (NamedQuantitySpec && NamedQuantitySpec) + return convertible_named(MP_UNITS_IS_CONST_EXPR(from), MP_UNITS_IS_CONST_EXPR(to)); + else if constexpr (DerivedQuantitySpec && DerivedQuantitySpec) + return are_ingredients_convertible(from, MP_UNITS_IS_CONST_EXPR(to)); + else if constexpr (DerivedQuantitySpec) { + auto res = explode(MP_UNITS_IS_CONST_EXPR(from)); if constexpr (NamedQuantitySpec) - return convertible_impl(res.quantity, To{}); - else if constexpr (requires { To{}._equation_; }) { - auto eq = explode_to_equation(To{}); + return convertible_impl(res.quantity, MP_UNITS_IS_CONST_EXPR(to)); + else if constexpr (requires { MP_UNITS_IS_CONST_EXPR(to)._equation_; }) { + auto eq = explode_to_equation(MP_UNITS_IS_CONST_EXPR(to)); return min(eq.result, convertible_impl(res.quantity, eq.equation)); } else - return are_ingredients_convertible(From{}, To{}); + return are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR(from), MP_UNITS_IS_CONST_EXPR(to)); } else if constexpr (DerivedQuantitySpec) { - auto res = explode(To{}); + auto res = explode(MP_UNITS_IS_CONST_EXPR(to)); if constexpr (NamedQuantitySpec) - return min(res.result, convertible_impl(From{}, res.quantity)); - else if constexpr (requires { From{}._equation_; }) - return min(res.result, convertible_impl(From{}._equation_, res.quantity)); + return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR(from), res.quantity)); + else if constexpr (requires { MP_UNITS_IS_CONST_EXPR(from)._equation_; }) + return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR(from)._equation_, res.quantity)); else - return min(res.result, are_ingredients_convertible(From{}, To{})); + return min(res.result, are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR(from), MP_UNITS_IS_CONST_EXPR(to))); } // NOLINTEND(bugprone-branch-clone) return no; @@ -1498,7 +1498,7 @@ MP_UNITS_EXPORT_BEGIN template [[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q q) { - return kind_of; + return kind_of; } [[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q) { return q; } diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index a0452b51..a2d3ae1a 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -288,9 +288,9 @@ template } -> Unit; } { - return detail::reference_t{}; + common_unit(get_unit(MP_UNITS_IS_CONST_EXPR(r1)), get_unit(MP_UNITS_IS_CONST_EXPR(r2)), get_unit(rest)...)>{}; } MP_UNITS_EXPORT_END diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index b00d4792..ba39dbb8 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -633,7 +633,7 @@ template template [[nodiscard]] consteval Unit auto common_unit(U1 u1, U2 u2) - requires(convertible(U1{}, U2{})) + requires(convertible(MP_UNITS_IS_CONST_EXPR(u1), MP_UNITS_IS_CONST_EXPR(u2))) { if constexpr (is_same_v) return u1; From b5c9dca61fe9e41cb038eb15b89035b0b51d6fbc Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:31:19 +0200 Subject: [PATCH 24/44] [naming] change some more names --- src/core/include/mp-units/framework/quantity_spec.h | 10 +++++----- src/core/include/mp-units/framework/symbol_text.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index af23ad74..8a3b4598 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -764,15 +764,15 @@ template template [[nodiscard]] consteval auto explode(Q, type_list, type_list) { - constexpr auto n = get_complexity(Num{}); + constexpr auto num = get_complexity(Num{}); constexpr auto den = get_complexity(Den{}); - constexpr auto max_compl = n > den ? n : den; + constexpr auto max_compl = num > den ? num : den; - if constexpr (max_compl == Complexity || ((n >= den && !requires { explode_to_equation(Num{}); }) || - (n < den && !requires { explode_to_equation(Den{}); }))) + if constexpr (max_compl == Complexity || ((num >= den && !requires { explode_to_equation(Num{}); }) || + (num < den && !requires { explode_to_equation(Den{}); }))) return explode_result{(map_power(Num{}) * ... * map_power(Nums{})) / (map_power(Den{}) * ... * map_power(Dens{}))}; else { - if constexpr (n >= den) { + if constexpr (num >= den) { constexpr auto res = explode_to_equation(Num{}); return explode((res.equation * ... * map_power(Nums{})) / (map_power(Den{}) * ... * map_power(Dens{}))) diff --git a/src/core/include/mp-units/framework/symbol_text.h b/src/core/include/mp-units/framework/symbol_text.h index d2875821..36dd4942 100644 --- a/src/core/include/mp-units/framework/symbol_text.h +++ b/src/core/include/mp-units/framework/symbol_text.h @@ -128,9 +128,9 @@ public: MP_UNITS_EXPECTS(detail::is_basic_literal_character_set(a)); } - constexpr symbol_text(const fixed_u8string& u, const fixed_string& text) : unicode_(u), ascii_(text) + constexpr symbol_text(const fixed_u8string& unicode, const fixed_string& ascii) : unicode_(unicode), ascii_(ascii) { - MP_UNITS_EXPECTS(detail::is_basic_literal_character_set(text.data_)); + MP_UNITS_EXPECTS(detail::is_basic_literal_character_set(ascii.data_)); } [[nodiscard]] constexpr const auto& unicode() const { return unicode_; } From 0b0d3345e59b440895c2ac12a2e294e64fe2157c Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:17:44 +0200 Subject: [PATCH 25/44] [clang-format] --- example/total_energy.cpp | 4 +- src/core/include/mp-units/bits/fmt.h | 8 +- src/core/include/mp-units/bits/hacks.h | 3 +- src/core/include/mp-units/bits/sudo_cast.h | 13 +- src/core/include/mp-units/format.h | 2 +- .../mp-units/framework/construction_helpers.h | 4 +- .../include/mp-units/framework/quantity.h | 8 +- .../mp-units/framework/quantity_point.h | 9 +- .../mp-units/framework/quantity_spec.h | 28 +++-- .../include/mp-units/framework/reference.h | 32 +++-- .../include/mp-units/framework/symbol_text.h | 3 +- src/core/include/mp-units/ostream.h | 2 +- .../include/mp-units/systems/si/math.h | 4 +- test/static/chrono_test.cpp | 6 +- test/static/custom_rep_test_min_impl.cpp | 11 +- test/static/quantity_point_test.cpp | 112 ++++++++++-------- test/static/quantity_test.cpp | 31 +++-- 17 files changed, 161 insertions(+), 119 deletions(-) diff --git a/example/total_energy.cpp b/example/total_energy.cpp index f0b961b9..44fbc22c 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -45,8 +45,8 @@ namespace { using namespace mp_units; -QuantityOf<(isq::mechanical_energy)> auto total_energy(QuantityOf<(isq::momentum)> auto p, QuantityOf<(isq::mass)> auto m, - QuantityOf<(isq::speed)> auto c) +QuantityOf<(isq::mechanical_energy)> auto total_energy(QuantityOf<(isq::momentum)> auto p, + QuantityOf<(isq::mass)> auto m, QuantityOf<(isq::speed)> auto c) { return isq::mechanical_energy(sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c)))); } diff --git a/src/core/include/mp-units/bits/fmt.h b/src/core/include/mp-units/bits/fmt.h index 1505ce25..3589bc11 100644 --- a/src/core/include/mp-units/bits/fmt.h +++ b/src/core/include/mp-units/bits/fmt.h @@ -189,7 +189,7 @@ constexpr void handle_dynamic_spec(int& value, fmt_arg_ref(value); } - MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("width is not integer")); + MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("width is not integer")); } }; -#ifdef _MSC_VER -#pragma warning( pop ) +#ifdef _MSC_VER +#pragma warning(pop) #endif MP_UNITS_EXPORT_END diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 09a6daab..9dd88298 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -82,7 +82,8 @@ #define MP_UNITS_TYPENAME typename #define MP_UNITS_EXPRESSION(x) (x) #define MP_UNITS_IS_VALUE(x) (x) -#define MP_UNITS_IS_CONST_EXPR(x) decltype(x){} +#define MP_UNITS_IS_CONST_EXPR(x) \ + decltype(x) {} #else diff --git a/src/core/include/mp-units/bits/sudo_cast.h b/src/core/include/mp-units/bits/sudo_cast.h index 0db70246..0873fd59 100644 --- a/src/core/include/mp-units/bits/sudo_cast.h +++ b/src/core/include/mp-units/bits/sudo_cast.h @@ -30,23 +30,24 @@ namespace mp_units::detail { -template +template struct has_common_type_impl : std::false_type {}; -template +template struct has_common_type_impl>, Ts...> : std::true_type {}; -template +template using has_common_type = typename has_common_type_impl::type; -template constexpr bool has_common_type_v = has_common_type_impl::value; +template +constexpr bool has_common_type_v = has_common_type_impl::value; template struct get_common_type : std::common_type {}; template -using maybe_common_type = MP_UNITS_TYPENAME std::conditional_t, - get_common_type, std::type_identity>::type; +using maybe_common_type = MP_UNITS_TYPENAME + std::conditional_t, get_common_type, std::type_identity>::type; /** * @brief Details about the conversion from one quantity to another. diff --git a/src/core/include/mp-units/format.h b/src/core/include/mp-units/format.h index d5fea4b6..6c76b5f8 100644 --- a/src/core/include/mp-units/format.h +++ b/src/core/include/mp-units/format.h @@ -452,7 +452,7 @@ class MP_UNITS_STD_FMT::formatter, Char> { } // user provided format quantity_formatter f{*this, out, q, locale}; - parse_quantity_specs(modifiers_format_str_.data(), modifiers_format_str_.data() + modifiers_format_str_.size(), f); + parse_quantity_specs(modifiers_format_str_.data(), modifiers_format_str_.data() + modifiers_format_str_.size(), f); return f.out; } diff --git a/src/core/include/mp-units/framework/construction_helpers.h b/src/core/include/mp-units/framework/construction_helpers.h index 43e44c81..9b5f9be9 100644 --- a/src/core/include/mp-units/framework/construction_helpers.h +++ b/src/core/include/mp-units/framework/construction_helpers.h @@ -51,8 +51,8 @@ template struct absolute_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity_point> operator()( - Rep&& lhs) const + [[nodiscard]] constexpr quantity_point> + operator()(Rep&& lhs) const { return quantity_point{quantity{std::forward(lhs), R{}}}; } diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index d957cb14..a5fada73 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -461,8 +461,8 @@ public: } friend constexpr decltype(auto) operator*=(Q1&& lhs, const Q2& rhs) { - lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ * - rhs.numerical_value_is_an_implementation_detail_; + lhs.numerical_value_is_an_implementation_detail_ = + lhs.numerical_value_is_an_implementation_detail_ * rhs.numerical_value_is_an_implementation_detail_; return std::forward(lhs); } @@ -490,8 +490,8 @@ public: friend constexpr decltype(auto) operator/=(Q1&& lhs, const Q2& rhs) { MP_UNITS_EXPECTS_DEBUG(rhs != rhs.zero()); - lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ - / rhs.numerical_value_is_an_implementation_detail_; + lhs.numerical_value_is_an_implementation_detail_ = + lhs.numerical_value_is_an_implementation_detail_ / rhs.numerical_value_is_an_implementation_detail_; return std::forward(lhs); } diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index 58b28b3f..c7d60319 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -54,14 +54,16 @@ template struct point_origin_interface { template requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+(PO, Q&& q) + [[nodiscard]] friend constexpr quantity_point operator+( + PO, Q&& q) { return quantity_point{std::forward(q), PO{}}; } template requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+(Q&& q, PO po) + [[nodiscard]] friend constexpr quantity_point operator+( + Q&& q, PO po) { return po + std::forward(q); } @@ -264,8 +266,7 @@ public: quantity_point& operator=(quantity_point&&) = default; template NewPO> - [[nodiscard]] constexpr QuantityPointOf<(NewPO{})> auto point_for( - NewPO new_origin) const + [[nodiscard]] constexpr QuantityPointOf<(NewPO{})> auto point_for(NewPO new_origin) const { if constexpr (is_same_v) return *this; diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 8a3b4598..664f26fc 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -673,7 +673,8 @@ template template [[nodiscard]] consteval bool ingredients_dimension_less(D1 lhs, D2 rhs) { - if constexpr (MP_UNITS_IS_CONST_EXPR(lhs) == MP_UNITS_IS_CONST_EXPR(rhs) || MP_UNITS_IS_CONST_EXPR(lhs) == dimension_one) + if constexpr (MP_UNITS_IS_CONST_EXPR(lhs) == MP_UNITS_IS_CONST_EXPR(rhs) || + MP_UNITS_IS_CONST_EXPR(lhs) == dimension_one) return false; else if constexpr (MP_UNITS_IS_CONST_EXPR(rhs) == dimension_one) return true; @@ -1344,15 +1345,21 @@ template using enum specs_convertible_result; return res == no ? no : yes; }; - if constexpr ((NamedQuantitySpec && NamedQuantitySpec) || + if constexpr ((NamedQuantitySpec && + NamedQuantitySpec) || get_complexity(MP_UNITS_IS_CONST_EXPR(from_kind)) == get_complexity(MP_UNITS_IS_CONST_EXPR(to_kind))) return convertible_impl(MP_UNITS_IS_CONST_EXPR(from_kind), MP_UNITS_IS_CONST_EXPR(to_kind)); - else if constexpr (get_complexity(MP_UNITS_IS_CONST_EXPR(from_kind)) > get_complexity(MP_UNITS_IS_CONST_EXPR(to_kind))) - return exploded_kind_result( - convertible_impl(get_kind_tree_root(explode(MP_UNITS_IS_CONST_EXPR(from_kind)).quantity), MP_UNITS_IS_CONST_EXPR(to_kind))); + else if constexpr (get_complexity(MP_UNITS_IS_CONST_EXPR(from_kind)) > + get_complexity(MP_UNITS_IS_CONST_EXPR(to_kind))) + return exploded_kind_result(convertible_impl( + get_kind_tree_root( + explode(MP_UNITS_IS_CONST_EXPR(from_kind)).quantity), + MP_UNITS_IS_CONST_EXPR(to_kind))); else - return exploded_kind_result( - convertible_impl(MP_UNITS_IS_CONST_EXPR(from_kind), get_kind_tree_root(explode(MP_UNITS_IS_CONST_EXPR(to_kind)).quantity))); + return exploded_kind_result(convertible_impl( + MP_UNITS_IS_CONST_EXPR(from_kind), + get_kind_tree_root( + explode(MP_UNITS_IS_CONST_EXPR(to_kind)).quantity))); } template @@ -1369,7 +1376,9 @@ template return no; else if constexpr (get_complexity(From{}) != get_complexity(To{})) { if constexpr (get_complexity(From{}) > get_complexity(To{})) - return convertible_impl(explode(MP_UNITS_IS_CONST_EXPR(from)).quantity, MP_UNITS_IS_CONST_EXPR(to)); + return convertible_impl( + explode(MP_UNITS_IS_CONST_EXPR(from)).quantity, + MP_UNITS_IS_CONST_EXPR(to)); else { auto res = explode(MP_UNITS_IS_CONST_EXPR(to)); return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR(from), res.quantity)); @@ -1388,7 +1397,8 @@ template else if constexpr (From::dimension != To::dimension) return no; else if constexpr (QuantityKindSpec || QuantityKindSpec) - return convertible_kinds(get_kind_tree_root(MP_UNITS_IS_CONST_EXPR(from)), get_kind_tree_root(MP_UNITS_IS_CONST_EXPR(to))); + return convertible_kinds(get_kind_tree_root(MP_UNITS_IS_CONST_EXPR(from)), + get_kind_tree_root(MP_UNITS_IS_CONST_EXPR(to))); else if constexpr (NestedQuantityKindSpecOf && get_kind_tree_root(To{}) == To{}) return yes; else if constexpr (NamedQuantitySpec && NamedQuantitySpec) diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index a2d3ae1a..c946476e 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -87,40 +87,47 @@ struct reference { } template - [[nodiscard]] friend consteval detail::reference_t operator*(reference, reference) + [[nodiscard]] friend consteval detail::reference_t + operator*(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t<(MP_UNITS_EXPRESSION(Q{} * get_quantity_spec(U2{}))), MP_UNITS_EXPRESSION(U{} * U2{})> operator*(reference, - U2) + [[nodiscard]] friend consteval detail::reference_t<(MP_UNITS_EXPRESSION(Q{} * get_quantity_spec(U2{}))), + MP_UNITS_EXPRESSION(U{} * U2{})> + operator*(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t operator*(U1, - reference) + [[nodiscard]] friend consteval detail::reference_t + operator*(U1, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t operator/(reference, reference) + [[nodiscard]] friend consteval detail::reference_t + operator/(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t operator/(reference, - U2) + [[nodiscard]] friend consteval detail::reference_t + operator/(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t operator/(U1, reference) + [[nodiscard]] friend consteval detail::reference_t + operator/(U1, reference) { return {}; } @@ -288,9 +295,10 @@ template } -> Unit; } { - return detail::reference_t{}; + return detail::reference_t< + common_quantity_spec(get_quantity_spec(MP_UNITS_IS_CONST_EXPR(r1)), get_quantity_spec(MP_UNITS_IS_CONST_EXPR(r2)), + get_quantity_spec(rest)...), + common_unit(get_unit(MP_UNITS_IS_CONST_EXPR(r1)), get_unit(MP_UNITS_IS_CONST_EXPR(r2)), get_unit(rest)...)>{}; } MP_UNITS_EXPORT_END diff --git a/src/core/include/mp-units/framework/symbol_text.h b/src/core/include/mp-units/framework/symbol_text.h index 36dd4942..a08a6844 100644 --- a/src/core/include/mp-units/framework/symbol_text.h +++ b/src/core/include/mp-units/framework/symbol_text.h @@ -128,7 +128,8 @@ public: MP_UNITS_EXPECTS(detail::is_basic_literal_character_set(a)); } - constexpr symbol_text(const fixed_u8string& unicode, const fixed_string& ascii) : unicode_(unicode), ascii_(ascii) + constexpr symbol_text(const fixed_u8string& unicode, const fixed_string& ascii) : + unicode_(unicode), ascii_(ascii) { MP_UNITS_EXPECTS(detail::is_basic_literal_character_set(ascii.data_)); } diff --git a/src/core/include/mp-units/ostream.h b/src/core/include/mp-units/ostream.h index d9ba6e5d..0b073225 100644 --- a/src/core/include/mp-units/ostream.h +++ b/src/core/include/mp-units/ostream.h @@ -90,7 +90,7 @@ std::basic_ostream& to_stream(std::basic_ostream& MP_UNITS_EXPORT_BEGIN template -concept is_mp_units_stream = requires (OStream os, T v) { detail::to_stream_impl(os, v); }; +concept is_mp_units_stream = requires(OStream os, T v) { detail::to_stream_impl(os, v); }; template std::basic_ostream& operator<<(std::basic_ostream& os, const T& v) diff --git a/src/systems/include/mp-units/systems/si/math.h b/src/systems/include/mp-units/systems/si/math.h index 0a863585..a7bc0cec 100644 --- a/src/systems/include/mp-units/systems/si/math.h +++ b/src/systems/include/mp-units/systems/si/math.h @@ -132,8 +132,8 @@ template common_reference(R1, R2); requires requires { atan2(v1, v2); } || requires { std::atan2(v1, v2); }; } -[[nodiscard]] inline QuantityOf auto atan2(const quantity& y, - const quantity& x) noexcept +[[nodiscard]] inline QuantityOf auto atan2( + const quantity& y, const quantity& x) noexcept { constexpr auto ref = common_reference(R1, R2); constexpr auto unit = get_unit(ref); diff --git a/test/static/chrono_test.cpp b/test/static/chrono_test.cpp index c4b03cd9..2785041f 100644 --- a/test/static/chrono_test.cpp +++ b/test/static/chrono_test.cpp @@ -63,7 +63,8 @@ static_assert(std::constructible_from>); static_assert(std::constructible_from, std::chrono::hours>); static_assert(std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert( + !std::constructible_from, std::chrono::seconds>); static_assert(!std::convertible_to>); static_assert( std::constructible_from, sys_seconds>); @@ -76,7 +77,8 @@ static_assert(std::convertible_to, sys_days>); static_assert(!std::constructible_from, sys_days>); static_assert(std::convertible_to>); -static_assert(!std::constructible_from, sys_seconds>); +static_assert( + !std::constructible_from, sys_seconds>); static_assert(!std::convertible_to>); // construction - different rep type (integral to a floating-point) diff --git a/test/static/custom_rep_test_min_impl.cpp b/test/static/custom_rep_test_min_impl.cpp index ccff6080..2e79c557 100644 --- a/test/static/custom_rep_test_min_impl.cpp +++ b/test/static/custom_rep_test_min_impl.cpp @@ -102,7 +102,8 @@ static_assert(creates_quantity, percent>); static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); -static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); +static_assert( + std::constructible_from>, quantity<(si::metre), min_impl>>); static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); @@ -122,8 +123,8 @@ static_assert(std::convertible_to, quantity<(si::m static_assert(std::constructible_from>, quantity<(si::metre), int>>); static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); -static_assert( - !std::constructible_from>, quantity<(si::metre), double>>); // narrowing conversion +static_assert(!std::constructible_from>, + quantity<(si::metre), double>>); // narrowing conversion static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); // min_impl -> T @@ -136,8 +137,8 @@ static_assert(std::convertible_to>, quant static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); static_assert(std::convertible_to>, quantity<(si::metre), double>>); -static_assert( - !std::constructible_from, quantity<(si::metre), min_impl>>); // narrowing conversion +static_assert(!std::constructible_from, + quantity<(si::metre), min_impl>>); // narrowing conversion static_assert(!std::convertible_to>, quantity<(si::metre), int>>); diff --git a/test/static/quantity_point_test.cpp b/test/static/quantity_point_test.cpp index fafbcb65..941f638b 100644 --- a/test/static/quantity_point_test.cpp +++ b/test/static/quantity_point_test.cpp @@ -236,7 +236,8 @@ static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); static_assert(is_of_type::point_origin, zeroth_point_origin_>>); -static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>>); +static_assert( + is_of_type::absolute_point_origin, zeroth_point_origin_>>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); @@ -257,7 +258,8 @@ static_assert(quantity_point::quantity_spec == i static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); static_assert(is_of_type::point_origin, struct mean_sea_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert( + is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); @@ -288,8 +290,9 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, - struct si::absolute_zero>); +static_assert( + is_of_type::point_origin, + struct si::absolute_zero>); static_assert( is_of_type::absolute_point_origin, struct si::absolute_zero>); @@ -303,8 +306,9 @@ static_assert(quantity_point::unit == si::kelvin); static_assert(is_of_type::point_origin, struct si::absolute_zero>); -static_assert(is_of_type::absolute_point_origin, - struct si::absolute_zero>); +static_assert( + is_of_type::absolute_point_origin, + struct si::absolute_zero>); static_assert(quantity_point::reference == si::degree_Celsius); static_assert(quantity_point::quantity_spec == @@ -545,7 +549,8 @@ static_assert(std::convertible_to, quantity_point<(i static_assert( std::constructible_from, quantity_point<(isq::speed[m / s])>>); -static_assert(std::convertible_to, quantity_point<(isq::length[m]) / isq::time[s]>>); +static_assert( + std::convertible_to, quantity_point<(isq::length[m]) / isq::time[s]>>); static_assert(std::constructible_from, quantity_point<(isq::speed[m / s])>>); static_assert(std::convertible_to, quantity_point>); @@ -577,12 +582,14 @@ static_assert(!std::convertible_to, quantity_po // mixed origins static_assert(!std::constructible_from, quantity_point<(si::metre)>>); static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert( + !std::constructible_from, quantity_point<(isq::height[m])>>); static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); static_assert(!std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); static_assert(!std::convertible_to, quantity_point<(si::metre)>>); -static_assert(!std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert( + !std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // same explicit origins @@ -593,26 +600,26 @@ static_assert( static_assert(std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert( - std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert(std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert( - std::convertible_to, quantity_point<(isq::height[km]), mean_sea_level>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[km]), mean_sea_level>>); static_assert(std::constructible_from, quantity_point<(isq::height[km]), mean_sea_level>>); -static_assert( - std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert( - std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert( - std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point<(si::metre), mean_sea_level>>); static_assert( std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); @@ -623,20 +630,21 @@ static_assert(std::convertible_to, quantity_point<(si::metre), ground_level>>); -static_assert(std::convertible_to, quantity_point<(si::metre), ground_level>>); - static_assert( - std::constructible_from, quantity_point<(isq::height[m]), ground_level>>); + std::convertible_to, quantity_point<(si::metre), ground_level>>); + +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), ground_level>>); static_assert( std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); static_assert(std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert( - std::convertible_to, quantity_point<(isq::height[km]), mean_sea_level>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[km]), mean_sea_level>>); -static_assert( - std::constructible_from, quantity_point<(isq::height[km]), ground_level>>); +static_assert(std::constructible_from, + quantity_point<(isq::height[km]), ground_level>>); static_assert( std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); @@ -657,11 +665,13 @@ static_assert( static_assert( std::constructible_from, quantity_point<(si::metre), ground_level>>); -static_assert(std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); +static_assert( + std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); static_assert( std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); -static_assert(std::convertible_to, quantity_point<(si::metre), ground_level>>); +static_assert( + std::convertible_to, quantity_point<(si::metre), ground_level>>); static_assert( std::constructible_from, quantity_point<(si::metre), other_ground_level>>); @@ -684,25 +694,25 @@ static_assert( static_assert(std::constructible_from, quantity_point<(isq::height[m]), zeroth_length>>); -static_assert( - std::convertible_to, quantity_point<(isq::length[m]), zeroth_length>>); +static_assert(std::convertible_to, + quantity_point<(isq::length[m]), zeroth_length>>); // quantity_specs with common_quantity_spec static_assert(!std::constructible_from, quantity_point<(isq::height[m]), zeroth_length>>); -static_assert( - !std::convertible_to, quantity_point<(isq::width[m]), zeroth_length>>); +static_assert(!std::convertible_to, + quantity_point<(isq::width[m]), zeroth_length>>); static_assert(!std::constructible_from, quantity_point<(isq::width[m]), zeroth_length>>); -static_assert( - !std::convertible_to, quantity_point<(isq::height[m]), zeroth_length>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), zeroth_length>>); // different dimensions -static_assert( - !std::constructible_from, quantity_point<(si::kelvin), (si::ice_point)>>); -static_assert( - !std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, + quantity_point<(si::kelvin), (si::ice_point)>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); // non-convertible quantity_specs static_assert(!std::constructible_from, @@ -748,16 +758,16 @@ static_assert(std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert( - std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert( - std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert( - std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point<(si::metre), mean_sea_level>>); static_assert( std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); @@ -793,8 +803,8 @@ static_assert( std::convertible_to>>); // incompatible origin -static_assert( - !std::constructible_from>, sys_seconds>); +static_assert(!std::constructible_from>, + sys_seconds>); static_assert( !std::convertible_to>>); #endif @@ -832,9 +842,11 @@ static_assert(quantity_point<(isq::height[m]), mean_sea_level>(tower_peak + 42 * static_assert(quantity_point<(isq::height[m]), ground_level>(mean_sea_level + 84 * m).quantity_from(ground_level) == 42 * m); -static_assert(quantity_point<(isq::height[m]), ground_level>(tower_peak + 42 * m).quantity_from(ground_level) == 84 * m); +static_assert(quantity_point<(isq::height[m]), ground_level>(tower_peak + 42 * m).quantity_from(ground_level) == + 84 * m); -static_assert(quantity_point<(isq::height[m]), tower_peak>(mean_sea_level + 42 * m).quantity_from(tower_peak) == -42 * m); +static_assert(quantity_point<(isq::height[m]), tower_peak>(mean_sea_level + 42 * m).quantity_from(tower_peak) == + -42 * m); static_assert(quantity_point<(isq::height[m]), tower_peak>(ground_level + 84 * m).quantity_from(tower_peak) == 42 * m); static_assert((mean_sea_level + 42 * m).point_for(mean_sea_level).quantity_from(mean_sea_level) == 42 * m); @@ -1642,8 +1654,8 @@ static_assert(is_of_type<(zero_Hz + 5 * isq::frequency[Hz]) - (zero_Hz + 10 / (2 static_assert((quantity_point{10 / (2 * isq::period_duration[s])} + 5 * isq::frequency[Hz]).quantity_from_zero() == 10 * isq::frequency[Hz]); -static_assert((10 / (2 * isq::period_duration[s]) + (zero_Hz + 5 * isq::frequency[Hz])) - .quantity_from_zero() == 10 * isq::frequency[Hz]); +static_assert((10 / (2 * isq::period_duration[s]) + (zero_Hz + 5 * isq::frequency[Hz])).quantity_from_zero() == + 10 * isq::frequency[Hz]); static_assert((quantity_point{5 * isq::frequency[Hz]} + 10 / (2 * isq::period_duration[s])).quantity_from_zero() == 10 * isq::frequency[Hz]); static_assert((5 * isq::frequency[Hz] + quantity_point{10 / (2 * isq::period_duration[s])}).quantity_from_zero() == diff --git a/test/static/quantity_test.cpp b/test/static/quantity_test.cpp index 6cd56773..3167b018 100644 --- a/test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -173,8 +173,9 @@ static_assert(!std::constructible_from, quantity<(isq static_assert(!std::convertible_to, quantity<(isq::length[m])>>); // implicit conversion from another quantity only if non-truncating -static_assert(std::constructible_from, quantity<(isq::length[m]), int>>); // int -> double OK -static_assert(std::convertible_to, quantity<(isq::length[m])>>); // int -> double OK +static_assert( + std::constructible_from, quantity<(isq::length[m]), int>>); // int -> double OK +static_assert(std::convertible_to, quantity<(isq::length[m])>>); // int -> double OK static_assert(!std::constructible_from, quantity<(isq::length[m])>>); // truncating double -> int not allowed @@ -188,7 +189,7 @@ static_assert(std::convertible_to, static_assert(!std::constructible_from, quantity<(isq::length[m]), int>>); // truncating metre -> - // kilometre not allowed + // kilometre not allowed static_assert( !std::convertible_to, quantity<(isq::length[km]), int>>); // truncating metre -> kilometre not allowed @@ -355,8 +356,8 @@ static_assert(quantity{123}.quantity_spec == kind_of); #if MP_UNITS_HOSTED using namespace std::chrono_literals; static_assert(std::is_same_v); -//return type for "s" is not specified. is double for msvc -//static_assert(std::is_same_v); +// return type for "s" is not specified. is double for msvc +// static_assert(std::is_same_v); static_assert(quantity{24h}.unit == si::hour); static_assert(quantity{24h}.quantity_spec == kind_of); #endif @@ -455,7 +456,7 @@ static_assert((std::uint8_t{255}* m %= 257 * m).numerical_value_in(m) != [] { #if !(defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 18 && defined MP_UNITS_MODULES) // next two lines trigger conversions warnings // (warning disabled in CMake for this file) -static_assert(((22 * m) *= 33.33).numerical_value_in(m) ==733); +static_assert(((22 * m) *= 33.33).numerical_value_in(m) == 733); static_assert(((22 * m) /= 3.33).numerical_value_in(m) == 6); static_assert(((22 * m) *= 33.33 * one).numerical_value_in(m) == 733); static_assert(((22 * m) /= 3.33 * one).numerical_value_in(m) == 6); @@ -850,14 +851,17 @@ static_assert(std::equality_comparable_with, quantity, quantity, int>>); static_assert(std::equality_comparable_with, quantity<(si::metre)>>); static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); -static_assert(std::equality_comparable_with, quantity, int>>); +static_assert( + std::equality_comparable_with, quantity, int>>); static_assert(std::equality_comparable_with, quantity<(si::metre)>>); static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); -static_assert(std::equality_comparable_with, quantity<(si::kilo<(si::metre)>), int>>); -static_assert(std::equality_comparable_with, quantity<(isq::height[(si::metre)])>>); -static_assert(std::equality_comparable_with, quantity<(isq::height[(si::metre)]), int>>); static_assert( - std::equality_comparable_with, quantity<(isq::height[(si::kilo<(si::metre)>)]), int>>); + std::equality_comparable_with, quantity<(si::kilo<(si::metre)>), int>>); +static_assert(std::equality_comparable_with, quantity<(isq::height[(si::metre)])>>); +static_assert( + std::equality_comparable_with, quantity<(isq::height[(si::metre)]), int>>); +static_assert(std::equality_comparable_with, + quantity<(isq::height[(si::kilo<(si::metre)>)]), int>>); template concept no_crossdimensional_equality = requires { @@ -1054,11 +1058,12 @@ static_assert(QuantityOf, isq::position_vector / isq::duration>) static_assert(QuantityOf[m / s]>, isq::position_vector / isq::duration>); static_assert(QuantityOf, isq::position_vector / isq::duration>); -static_assert(QuantityOf); // kind of +static_assert(QuantityOf); // kind of static_assert(QuantityOf[m]), (isq::height)>); // kind of static_assert(!QuantityOf); // different kinds static_assert(!QuantityOf); // different kinds static_assert(QuantityOf); -static_assert(QuantityOf); // derived unnamed quantity +static_assert( + QuantityOf); // derived unnamed quantity } // namespace From 61ada08c3bc93c3081ae8f4f6d2a622bd9f2c24d Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:20:11 +0200 Subject: [PATCH 26/44] [msvc][conan] update test_package.cpp --- test_package/test_package.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_package/test_package.cpp b/test_package/test_package.cpp index 72a27f88..0ab5bdb0 100644 --- a/test_package/test_package.cpp +++ b/test_package/test_package.cpp @@ -28,7 +28,7 @@ using namespace mp_units; -constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) +constexpr QuantityOf auto avg_speed(QuantityOf<(isq::distance)> auto d, QuantityOf<(isq::duration)> auto t) { return d / t; } From af077ef3c59e802ed6b513ff7de770d5e4019e51 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:20:54 +0200 Subject: [PATCH 27/44] [msvc][fix] revert changes in example and test folder --- example/avg_speed.cpp | 12 +- example/capacitor_time_curve.cpp | 2 +- example/clcpp_response.cpp | 4 +- example/currency.cpp | 14 +- example/glide_computer.cpp | 10 +- .../include/glide_computer_lib.h | 2 +- example/hello_units.cpp | 2 +- example/include/geographic.h | 8 +- example/kalman_filter/kalman.h | 16 +- example/spectroscopy_units.cpp | 8 +- example/storage_tank.cpp | 10 +- example/total_energy.cpp | 18 +- example/unmanned_aerial_vehicle.cpp | 1 - test/runtime/CMakeLists.txt | 10 +- test/static/chrono_test.cpp | 76 +- test/static/concepts_test.cpp | 242 +++--- test/static/custom_rep_test_min_impl.cpp | 67 +- test/static/dimension_test.cpp | 2 +- test/static/quantity_point_test.cpp | 795 +++++++++--------- test/static/quantity_spec_test.cpp | 4 +- test/static/quantity_test.cpp | 204 +++-- test/static/reference_test.cpp | 6 +- test/static/si_test.cpp | 2 +- test/static/unit_test.cpp | 4 +- 24 files changed, 749 insertions(+), 770 deletions(-) diff --git a/example/avg_speed.cpp b/example/avg_speed.cpp index 11072bb3..dc2d24d2 100644 --- a/example/avg_speed.cpp +++ b/example/avg_speed.cpp @@ -45,26 +45,26 @@ namespace { using namespace mp_units; -constexpr quantity fixed_int_si_avg_speed(quantity<(si::metre), int> d, - quantity<(si::second), int> t) +constexpr quantity fixed_int_si_avg_speed(quantity d, + quantity t) { return d / t; } -constexpr quantity fixed_double_si_avg_speed(quantity<(si::metre)> d, quantity<(si::second)> t) +constexpr quantity fixed_double_si_avg_speed(quantity d, quantity t) { return d / t; } -constexpr QuantityOf<(isq::speed)> auto avg_speed(QuantityOf<(isq::length)> auto d, QuantityOf<(isq::time)> auto t) +constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) { return d / t; } -template D, QuantityOf<(isq::time)> T, QuantityOf<(isq::speed)> V> +template D, QuantityOf T, QuantityOf V> void print_result(D distance, T duration, V speed) { - const auto result_in_kmph = speed.force_in((si::kilo<(si::metre)> / non_si::hour)); + const auto result_in_kmph = speed.force_in(si::kilo / non_si::hour); std::cout << "Average speed of a car that makes " << distance << " in " << duration << " is " << result_in_kmph << ".\n"; } diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp index 2f2f7fdb..4cf363fe 100644 --- a/example/capacitor_time_curve.cpp +++ b/example/capacitor_time_curve.cpp @@ -48,7 +48,7 @@ int main() constexpr auto RR = isq::resistance(4.7 * si::kilo); for (auto tt = 0 * ms; tt <= 50 * ms; ++tt) { - const QuantityOf<(isq::voltage)> auto Vt = V0 * exp(dimensionless(-tt / (RR * CC))); + const QuantityOf auto Vt = V0 * exp(dimensionless(-tt / (RR * CC))); // TODO try to make the below work instead // const QuantityOf auto Vt = V0 * exp(-tt / (RR * CC)); diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index 9a74de52..42ed6d0b 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -44,8 +44,8 @@ void simple_quantities() using namespace mp_units::si; using namespace mp_units::international; - using distance = quantity<(isq::distance[kilo])>; - using duration = quantity<(isq::duration[second])>; + using distance = quantity]>; + using duration = quantity; constexpr distance km = 1. * kilo; constexpr distance miles = 1. * mile; diff --git a/example/currency.cpp b/example/currency.cpp index 0eb46040..6f280659 100644 --- a/example/currency.cpp +++ b/example/currency.cpp @@ -90,11 +90,11 @@ template #endif -// template auto To, ReferenceOf auto From, typename Rep> -// quantity exchange_to(quantity q) -// { -// return static_cast(exchange_rate() * q.numerical_value()) * To; -// } +template auto To, ReferenceOf auto From, typename Rep> +quantity exchange_to(quantity q) +{ + return static_cast(exchange_rate() * q.numerical_value()) * To; +} template auto To, ReferenceOf auto From, auto PO, typename Rep> quantity_point exchange_to(quantity_point q) @@ -107,8 +107,8 @@ int main() { using namespace unit_symbols; - const mp_units::quantity_point price_usd{100 * USD}; - const mp_units::quantity_point price_euro = exchange_to(price_usd); + const quantity_point price_usd{100 * USD}; + const quantity_point price_euro = exchange_to(price_usd); std::cout << price_usd.quantity_from_zero() << " -> " << price_euro.quantity_from_zero() << "\n"; // std::cout << price_usd.quantity_from_zero() + price_euro.quantity_from_zero() << "\n"; // does diff --git a/example/glide_computer.cpp b/example/glide_computer.cpp index f06062fe..133a7713 100644 --- a/example/glide_computer.cpp +++ b/example/glide_computer.cpp @@ -169,7 +169,7 @@ void example() const auto gliders = get_gliders(); const auto waypoints = get_waypoints(); const auto weather_conditions = get_weather_conditions(); - const task glider_task = {waypoints[0], waypoints[1], waypoints[0]}; + const task t = {waypoints[0], waypoints[1], waypoints[0]}; const aircraft_tow tow = {400 * m, 1.6 * m / s}; const timestamp start_time(std::chrono::system_clock::now()); @@ -177,16 +177,16 @@ void example() print(gliders); print(waypoints); print(weather_conditions); - print(glider_task); + print(t); print(tow); - for (const auto& glider : gliders) { + for (const auto& g : gliders) { for (const auto& c : weather_conditions) { - const std::string txt = "Scenario: Glider = " + glider.name + ", Weather = " + c.first; + const std::string txt = "Scenario: Glider = " + g.name + ", Weather = " + c.first; std::cout << txt << "\n"; std::cout << MP_UNITS_STD_FMT::format("{0:=^{1}}\n\n", "", txt.size()); - estimate(start_time, glider, c.second, glider_task, sfty, tow); + estimate(start_time, g, c.second, t, sfty, tow); std::cout << "\n\n"; } diff --git a/example/glide_computer_lib/include/glide_computer_lib.h b/example/glide_computer_lib/include/glide_computer_lib.h index e8fafbf3..5e2ac4db 100644 --- a/example/glide_computer_lib/include/glide_computer_lib.h +++ b/example/glide_computer_lib/include/glide_computer_lib.h @@ -90,7 +90,7 @@ struct glider { std::array polar; }; -constexpr mp_units::QuantityOf<(mp_units::dimensionless)> auto glide_ratio(const glider::polar_point& polar) +constexpr mp_units::QuantityOf auto glide_ratio(const glider::polar_point& polar) { return polar.v / -polar.climb; } diff --git a/example/hello_units.cpp b/example/hello_units.cpp index 95b5e6d6..e635bc25 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -45,7 +45,7 @@ import mp_units; using namespace mp_units; -constexpr QuantityOf<(isq::speed)> auto avg_speed(QuantityOf<(isq::length)> auto d, QuantityOf<(isq::time)> auto t) +constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) { return d / t; } diff --git a/example/include/geographic.h b/example/include/geographic.h index 4f7ca94a..ba26b3f1 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -79,10 +79,10 @@ inline constexpr struct prime_meridian final : mp_units::absolute_point_origin -using latitude = mp_units::quantity_point<(mp_units::si::degree), equator, ranged_representation>; +using latitude = mp_units::quantity_point>; template -using longitude = mp_units::quantity_point<(mp_units::si::degree), prime_meridian, ranged_representation>; +using longitude = mp_units::quantity_point>; template std::basic_ostream& operator<<(std::basic_ostream& os, const latitude& lat) @@ -176,7 +176,7 @@ template distance spherical_distance(position from, position to) { using namespace mp_units; - constexpr quantity earth_radius = 6'371 * isq::radius[si::kilo<(si::metre)>]; + constexpr quantity earth_radius = 6'371 * isq::radius[si::kilo]; using si::sin, si::cos, si::asin, si::acos; @@ -193,7 +193,7 @@ distance spherical_distance(position from, position to) // const auto central_angle = 2 * asin(sqrt(0.5 - cos(to_lat - from_lat) / 2 + cos(from_lat) * cos(to_lat) * (1 // - cos(lon2_rad - from_lon)) / 2)); - return quantity_cast<(isq::distance)>(earth_radius * central_angle); + return quantity_cast(earth_radius * central_angle); } else { // the haversine formula const quantity sin_lat = sin((to_lat - from_lat) / 2); diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index e959e3d3..6e629477 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -116,15 +116,15 @@ template } // state update -template K> +template K> requires(implicitly_convertible(QM::quantity_spec, QP::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, K gain) { return system_state{get<0>(predicted) + gain * (measured - get<0>(predicted))}; } -template K, - mp_units::QuantityOf<(mp_units::isq::time)> T> +template K, + mp_units::QuantityOf T> requires(implicitly_convertible(QM::quantity_spec, QP1::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, std::array gain, T interval) @@ -135,7 +135,7 @@ template K, mp_units::QuantityOf<(mp_units::isq::time)> T> + mp_units::QuantityOf K, mp_units::QuantityOf T> requires(implicitly_convertible(QM::quantity_spec, QP1::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, std::array gain, T interval) @@ -147,13 +147,13 @@ template K> +template K> [[nodiscard]] constexpr Q covariance_update(Q uncertainty, K gain) { return (1 * mp_units::one - gain) * uncertainty; } -template K> +template K> [[nodiscard]] constexpr system_state_estimate state_estimate_update( const system_state_estimate& previous, QP measurement, K gain) { @@ -162,7 +162,7 @@ template T> +template T> [[nodiscard]] constexpr system_state state_extrapolation(const system_state& estimated, T interval) { auto to_quantity = [](const auto& qp) { return qp.quantity_ref_from(qp.point_origin); }; @@ -171,7 +171,7 @@ template return system_state{qp1, qp2}; } -template T> +template T> [[nodiscard]] constexpr system_state state_extrapolation(const system_state& estimated, T interval) { diff --git a/example/spectroscopy_units.cpp b/example/spectroscopy_units.cpp index d618b3b3..3fce6a8b 100644 --- a/example/spectroscopy_units.cpp +++ b/example/spectroscopy_units.cpp @@ -54,8 +54,8 @@ constexpr auto h = 1 * si::si2019::planck_constant; constexpr auto kb = 1 * si::si2019::boltzmann_constant; // prints quantities in the resulting unit -template T1, QuantityOf<(isq::wavenumber)> T2, QuantityOf<(isq::frequency)> T3, - QuantityOf<(isq::thermodynamic_temperature)> T4, QuantityOf<(isq::wavelength)> T5> +template T1, QuantityOf T2, QuantityOf T3, + QuantityOf T4, QuantityOf T5> void print_line(const std::tuple& t) { std::cout << MP_UNITS_STD_FMT::format( @@ -65,8 +65,8 @@ void print_line(const std::tuple& t) // prints quantities in semi-SI units // (eV is not an official SI unit) -template T1, QuantityOf<(isq::wavenumber)> T2, QuantityOf<(isq::frequency)> T3, - QuantityOf<(isq::thermodynamic_temperature)> T4, QuantityOf<(isq::wavelength)> T5> +template T1, QuantityOf T2, QuantityOf T3, + QuantityOf T4, QuantityOf T5> void print_line_si(const std::tuple& t) { std::cout << MP_UNITS_STD_FMT::format( diff --git a/example/storage_tank.cpp b/example/storage_tank.cpp index 9e2c1020..ad9f7580 100644 --- a/example/storage_tank.cpp +++ b/example/storage_tank.cpp @@ -77,10 +77,10 @@ public: density_ = density; } - [[nodiscard]] constexpr QuantityOf<(isq::weight)> auto filled_weight() const + [[nodiscard]] constexpr QuantityOf auto filled_weight() const { const auto volume = isq::volume(base_ * height_); // TODO check if we can remove that cast - const QuantityOf<(isq::mass)> auto mass = density_ * volume; + const QuantityOf auto mass = density_ * volume; return isq::weight(mass * g); } @@ -130,9 +130,9 @@ int main() const quantity spare_capacity = tank.spare_capacity(measured_mass); const quantity filled_weight = tank.filled_weight(); - const QuantityOf<(isq::mass_change_rate)> auto input_flow_rate = measured_mass / fill_time; - const QuantityOf<(isq::speed)> auto float_rise_rate = fill_level / fill_time; - const QuantityOf<(isq::time)> auto fill_time_left = (height / fill_level - 1 * one) * fill_time; + const QuantityOf auto input_flow_rate = measured_mass / fill_time; + const QuantityOf auto float_rise_rate = fill_level / fill_time; + const QuantityOf auto fill_time_left = (height / fill_level - 1 * one) * fill_time; const quantity fill_ratio = fill_level / height; diff --git a/example/total_energy.cpp b/example/total_energy.cpp index 44fbc22c..bcd149d6 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -45,8 +45,8 @@ namespace { using namespace mp_units; -QuantityOf<(isq::mechanical_energy)> auto total_energy(QuantityOf<(isq::momentum)> auto p, - QuantityOf<(isq::mass)> auto m, QuantityOf<(isq::speed)> auto c) +QuantityOf auto total_energy(QuantityOf auto p, QuantityOf auto m, + QuantityOf auto c) { return isq::mechanical_energy(sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c)))); } @@ -59,19 +59,19 @@ void si_example() const quantity c2 = pow<2>(c); const quantity p1 = isq::momentum(4. * GeV / c); - const QuantityOf<(isq::mass)> auto m1 = 3. * GeV / c2; - const quantity E1 = total_energy(p1, m1, c); + const QuantityOf auto m1 = 3. * GeV / c2; + const quantity E = total_energy(p1, m1, c); std::cout << "\n*** SI units (c = " << c << " = " << c.in(si::metre / s) << ") ***\n"; std::cout << "\n[in `GeV` and `c`]\n" << "p = " << p1 << "\n" << "m = " << m1 << "\n" - << "E = " << E1 << "\n"; + << "E = " << E << "\n"; const quantity p2 = p1.in(GeV / (m / s)); - const quantity metre2 = m1.in(GeV / pow<2>(m / s)); - const quantity E2 = total_energy(p2, metre2, c).in(GeV); + const quantity m2 = m1.in(GeV / pow<2>(m / s)); + const quantity E2 = total_energy(p2, m2, c).in(GeV); std::cout << "\n[in `GeV`]\n" << "p = " << p2 << "\n" @@ -79,8 +79,8 @@ void si_example() << "E = " << E2 << "\n"; const quantity p3 = p1.in(kg * m / s); - const quantity metre3 = m1.in(kg); - const quantity E3 = total_energy(p3, metre3, c).in(J); + const quantity m3 = m1.in(kg); + const quantity E3 = total_energy(p3, m3, c).in(J); std::cout << "\n[in SI base units]\n" << "p = " << p3 << "\n" diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index 8a8648d5..3e26ac08 100644 --- a/example/unmanned_aerial_vehicle.cpp +++ b/example/unmanned_aerial_vehicle.cpp @@ -70,7 +70,6 @@ constexpr const char* to_text(earth_gravity_model m) return "EGM2008-1"; } assert(false && "unsupported enum value"); - return "unsupported enum value"; } template diff --git a/test/runtime/CMakeLists.txt b/test/runtime/CMakeLists.txt index 70e13650..d79ed54b 100644 --- a/test/runtime/CMakeLists.txt +++ b/test/runtime/CMakeLists.txt @@ -37,11 +37,11 @@ if(${projectPrefix}BUILD_CXX_MODULES) endif() target_link_libraries(unit_tests_runtime PRIVATE mp-units::mp-units Catch2::Catch2WithMain) -# if(${projectPrefix}DEV_BUILD_LA) -# find_package(wg21_linear_algebra REQUIRED) -# target_sources(unit_tests_runtime PRIVATE linear_algebra_test.cpp) -# target_link_libraries(unit_tests_runtime PRIVATE wg21_linear_algebra::wg21_linear_algebra) -# endif() +if(${projectPrefix}DEV_BUILD_LA) + find_package(wg21_linear_algebra REQUIRED) + target_sources(unit_tests_runtime PRIVATE linear_algebra_test.cpp) + target_link_libraries(unit_tests_runtime PRIVATE wg21_linear_algebra::wg21_linear_algebra) +endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options( diff --git a/test/static/chrono_test.cpp b/test/static/chrono_test.cpp index 2785041f..9f3b1901 100644 --- a/test/static/chrono_test.cpp +++ b/test/static/chrono_test.cpp @@ -57,43 +57,41 @@ static_assert(!QuantityPoint); // construction - same rep type static_assert( - std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); + std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); static_assert( - !std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); + std::constructible_from, sys_seconds>); static_assert( - std::constructible_from, sys_seconds>); -static_assert( - !std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(!std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(!std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert( - !std::constructible_from, sys_seconds>); -static_assert(!std::convertible_to>); + !std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(!std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(!std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(!std::constructible_from, sys_seconds>); +static_assert(!std::convertible_to>); // construction - different rep type (integral to a floating-point) -static_assert(std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); static_assert(quantity{1s} == 1 * s); static_assert(quantity{1s} == 1 * s); @@ -109,13 +107,13 @@ static_assert(is_of_type>); -static_assert(std::convertible_to, std::chrono::seconds>); -static_assert(std::constructible_from>); -static_assert(std::convertible_to, std::chrono::hours>); + std::constructible_from>); +static_assert(std::convertible_to, std::chrono::seconds>); +static_assert(std::constructible_from>); +static_assert(std::convertible_to, std::chrono::hours>); static_assert( - std::constructible_from>); -static_assert(std::convertible_to, sys_seconds>); + std::constructible_from>); +static_assert(std::convertible_to, sys_seconds>); // units mapping static_assert(quantity{1ns} == 1 * ns); diff --git a/test/static/concepts_test.cpp b/test/static/concepts_test.cpp index 52a1f96a..06b20699 100644 --- a/test/static/concepts_test.cpp +++ b/test/static/concepts_test.cpp @@ -83,7 +83,7 @@ inline constexpr auto speed = isq::length / isq::time; static_assert(QuantitySpec); static_assert(QuantitySpec); static_assert(QuantitySpec); -static_assert(QuantitySpec)>); +static_assert(QuantitySpec)>); static_assert(QuantitySpec); static_assert(QuantitySpec(isq::length))>); static_assert(QuantitySpec); @@ -95,7 +95,7 @@ static_assert(!QuantitySpec); static_assert(detail::NamedQuantitySpec); static_assert(detail::NamedQuantitySpec); static_assert(detail::NamedQuantitySpec); -static_assert(!detail::NamedQuantitySpec)>>); +static_assert(!detail::NamedQuantitySpec)>>); static_assert(!detail::NamedQuantitySpec); static_assert(!detail::NamedQuantitySpec(isq::length))>); static_assert(detail::NamedQuantitySpec); @@ -106,7 +106,7 @@ static_assert(!detail::NamedQuantitySpec); // DerivedQuantitySpec static_assert(!detail::DerivedQuantitySpec); static_assert(!detail::DerivedQuantitySpec); -static_assert(!detail::DerivedQuantitySpec)>); +static_assert(!detail::DerivedQuantitySpec)>); static_assert(!detail::DerivedQuantitySpec); static_assert(detail::DerivedQuantitySpec); static_assert(detail::DerivedQuantitySpec(isq::length))>); @@ -118,7 +118,7 @@ static_assert(!detail::DerivedQuantitySpec); // QuantityKindSpec static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec); -static_assert(detail::QuantityKindSpec)>>); +static_assert(detail::QuantityKindSpec)>>); static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec(isq::length))>); @@ -133,7 +133,7 @@ static_assert(!detail::QuantityKindSpec); // Unit static_assert(Unit); static_assert(Unit); -static_assert(Unit)>); +static_assert(Unit)>); static_assert(Unit); static_assert(Unit); static_assert(Unit); @@ -144,11 +144,11 @@ static_assert(Unit); static_assert(Unit, struct si::second>>); static_assert(Unit>>); static_assert(Unit); -static_assert(!Unit>>); +static_assert(!Unit>>); static_assert(!Unit>); static_assert(!Unit>); -static_assert(!Unit>>); -static_assert(!Unit, (si::second)>>); +static_assert(!Unit>>); +static_assert(!Unit, si::second>>); static_assert(!Unit); static_assert(!Unit); #if MP_UNITS_HOSTED @@ -159,7 +159,7 @@ static_assert(!Unit); static_assert(PrefixableUnit); static_assert(PrefixableUnit); static_assert(!PrefixableUnit); -static_assert(!PrefixableUnit)>); +static_assert(!PrefixableUnit)>); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit * si::second)>); @@ -169,11 +169,11 @@ static_assert(PrefixableUnit); static_assert(!PrefixableUnit, struct si::second>>); static_assert(!PrefixableUnit>>); static_assert(!PrefixableUnit); -static_assert(!PrefixableUnit>>); +static_assert(!PrefixableUnit>>); static_assert(!PrefixableUnit>); static_assert(!PrefixableUnit>); -static_assert(!PrefixableUnit>>); -static_assert(!PrefixableUnit, (si::second)>>); +static_assert(!PrefixableUnit>>); +static_assert(!PrefixableUnit, si::second>>); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit); #if MP_UNITS_HOSTED @@ -184,7 +184,7 @@ static_assert(!PrefixableUnit); static_assert(AssociatedUnit); static_assert(!AssociatedUnit); static_assert(AssociatedUnit); -static_assert(AssociatedUnit)>); +static_assert(AssociatedUnit)>); static_assert(AssociatedUnit); static_assert(AssociatedUnit); static_assert(AssociatedUnit * si::second)>); @@ -194,11 +194,11 @@ static_assert(AssociatedUnit); static_assert(AssociatedUnit, struct si::second>>); static_assert(AssociatedUnit>>); static_assert(AssociatedUnit); -static_assert(!AssociatedUnit>>); +static_assert(!AssociatedUnit>>); static_assert(!AssociatedUnit>); static_assert(!AssociatedUnit>); -static_assert(!AssociatedUnit>>); -static_assert(!AssociatedUnit, (si::second)>>); +static_assert(!AssociatedUnit>>); +static_assert(!AssociatedUnit, si::second>>); static_assert(!AssociatedUnit); static_assert(!AssociatedUnit); #if MP_UNITS_HOSTED @@ -206,19 +206,19 @@ static_assert(!AssociatedUnit); #endif // UnitOf -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); static_assert(!UnitOf); -static_assert(!UnitOf); -static_assert(!UnitOf); +static_assert(!UnitOf); +static_assert(!UnitOf); // Reference static_assert(Reference); @@ -228,32 +228,32 @@ static_assert(Reference); static_assert(Reference); static_assert(!Reference); static_assert(!Reference); -static_assert(!Reference)>); +static_assert(!Reference)>); static_assert(!Reference); static_assert(!Reference); // ReferenceOf -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); static_assert(ReferenceOf); static_assert(ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(!ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(!ReferenceOf); // Representation static_assert(Representation); @@ -278,57 +278,57 @@ static_assert(!RepresentationOf); #endif // Quantity -static_assert(Quantity>); -static_assert(Quantity>); -static_assert(Quantity>); -static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); #if MP_UNITS_HOSTED static_assert(!Quantity); #endif -static_assert(!Quantity>); +static_assert(!Quantity>); static_assert(!Quantity); // QuantityOf -static_assert(QuantityOf, (isq::length)>); -static_assert(QuantityOf, (isq::radius)>); -static_assert(!QuantityOf, (isq::length)>); -static_assert(QuantityOf, (isq::length)>); -static_assert(!QuantityOf, (isq::radius)>); -static_assert(QuantityOf, (isq::length)>); -static_assert(QuantityOf, (isq::radius)>); -static_assert(!QuantityOf, (isq::dim_length)>); +static_assert(QuantityOf, isq::length>); +static_assert(QuantityOf, isq::radius>); +static_assert(!QuantityOf, isq::length>); +static_assert(QuantityOf, isq::length>); +static_assert(!QuantityOf, isq::radius>); +static_assert(QuantityOf, isq::length>); +static_assert(QuantityOf, isq::radius>); +static_assert(!QuantityOf, isq::dim_length>); static_assert(QuantityOf, dimensionless>); static_assert(QuantityOf, dimensionless>); -static_assert(QuantityOf, (isq::rotation)>); -static_assert(QuantityOf, dimensionless>); -static_assert(QuantityOf, (isq::angular_measure)>); -static_assert(!QuantityOf, dimensionless>); -static_assert(QuantityOf, (isq::angular_measure)>); -static_assert(!QuantityOf, dimensionless>); -static_assert(QuantityOf, (isq::rotation)>); -static_assert(QuantityOf, (isq::angular_measure)>); -static_assert(!QuantityOf, (isq::rotation)>); -static_assert(!QuantityOf, (isq::angular_measure)>); +static_assert(QuantityOf, isq::rotation>); +static_assert(QuantityOf, dimensionless>); +static_assert(QuantityOf, isq::angular_measure>); +static_assert(!QuantityOf, dimensionless>); +static_assert(QuantityOf, isq::angular_measure>); +static_assert(!QuantityOf, dimensionless>); +static_assert(QuantityOf, isq::rotation>); +static_assert(QuantityOf, isq::angular_measure>); +static_assert(!QuantityOf, isq::rotation>); +static_assert(!QuantityOf, isq::angular_measure>); // QuantityLike #if MP_UNITS_HOSTED static_assert(QuantityLike); static_assert(QuantityLike); #endif -static_assert(!QuantityLike>); -static_assert(!QuantityLike>); +static_assert(!QuantityLike>); +static_assert(!QuantityLike>); static_assert(!QuantityLike); // QuantityPoint -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); static_assert(!QuantityPoint); -static_assert(!QuantityPoint>); +static_assert(!QuantityPoint>); static_assert(!QuantityPoint); static_assert(!QuantityPoint); #if MP_UNITS_HOSTED @@ -338,35 +338,35 @@ static_assert(!QuantityPoint> static_assert(!QuantityPoint); // QuantityPointOf -static_assert(QuantityPointOf, (isq::length)>); -static_assert(QuantityPointOf, (isq::radius)>); -static_assert(QuantityPointOf, (isq::length)>); -static_assert(!QuantityPointOf, (isq::radius)>); -static_assert(QuantityPointOf, (isq::length)>); -static_assert(QuantityPointOf, (isq::radius)>); -static_assert(QuantityPointOf, (isq::length)>); -static_assert(QuantityPointOf, (isq::radius)>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, isq::length>); +static_assert(QuantityPointOf, isq::radius>); +static_assert(QuantityPointOf, isq::length>); +static_assert(!QuantityPointOf, isq::radius>); +static_assert(QuantityPointOf, isq::length>); +static_assert(QuantityPointOf, isq::radius>); +static_assert(QuantityPointOf, isq::length>); +static_assert(QuantityPointOf, isq::radius>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); // PointOrigin static_assert(PointOrigin); static_assert(PointOrigin); -static_assert(!PointOrigin>); +static_assert(!PointOrigin>); static_assert(!PointOrigin>); -static_assert(!PointOrigin>); -static_assert(!PointOrigin>); -static_assert(!PointOrigin>); +static_assert(!PointOrigin>); +static_assert(!PointOrigin>); +static_assert(!PointOrigin>); static_assert(!PointOrigin); #if MP_UNITS_HOSTED static_assert(!PointOrigin); @@ -375,38 +375,38 @@ static_assert(!PointOrigin>); static_assert(!PointOrigin); // PointOriginFor -static_assert(PointOriginFor); -static_assert(PointOriginFor); -static_assert(!PointOriginFor); -static_assert(PointOriginFor); -static_assert(PointOriginFor); -static_assert(!PointOriginFor); -static_assert(!PointOriginFor, (isq::length)>); -static_assert(!PointOriginFor, (isq::radius)>); -static_assert(!PointOriginFor, (isq::time)>); -static_assert(!PointOriginFor, (isq::length)>); -static_assert(!PointOriginFor, (isq::radius)>); -static_assert(!PointOriginFor, (isq::time)>); -static_assert(!PointOriginFor, (isq::length)>); -static_assert(!PointOriginFor, (isq::radius)>); -static_assert(!PointOriginFor, (isq::time)>); -static_assert(!PointOriginFor, (isq::length)>); -static_assert(!PointOriginFor, (isq::radius)>); -static_assert(!PointOriginFor, (isq::time)>); -static_assert(!PointOriginFor); +static_assert(PointOriginFor); +static_assert(PointOriginFor); +static_assert(!PointOriginFor); +static_assert(PointOriginFor); +static_assert(PointOriginFor); +static_assert(!PointOriginFor); +static_assert(!PointOriginFor, isq::length>); +static_assert(!PointOriginFor, isq::radius>); +static_assert(!PointOriginFor, isq::time>); +static_assert(!PointOriginFor, isq::length>); +static_assert(!PointOriginFor, isq::radius>); +static_assert(!PointOriginFor, isq::time>); +static_assert(!PointOriginFor, isq::length>); +static_assert(!PointOriginFor, isq::radius>); +static_assert(!PointOriginFor, isq::time>); +static_assert(!PointOriginFor, isq::length>); +static_assert(!PointOriginFor, isq::radius>); +static_assert(!PointOriginFor, isq::time>); +static_assert(!PointOriginFor); #if MP_UNITS_HOSTED -static_assert(!PointOriginFor); -static_assert(!PointOriginFor, (isq::length)>); +static_assert(!PointOriginFor); +static_assert(!PointOriginFor, isq::length>); #endif -static_assert(!PointOriginFor); +static_assert(!PointOriginFor); // QuantityPointLike #if MP_UNITS_HOSTED static_assert(QuantityPointLike>); static_assert(!QuantityPointLike); #endif -static_assert(!QuantityPointLike>); -static_assert(!QuantityPointLike>); +static_assert(!QuantityPointLike>); +static_assert(!QuantityPointLike>); static_assert(!QuantityPointLike); } // namespace diff --git a/test/static/custom_rep_test_min_impl.cpp b/test/static/custom_rep_test_min_impl.cpp index 2e79c557..8e8c3b7c 100644 --- a/test/static/custom_rep_test_min_impl.cpp +++ b/test/static/custom_rep_test_min_impl.cpp @@ -78,18 +78,18 @@ static_assert(Representation>); static_assert(Representation>); // construction from a value is not allowed -static_assert(!std::constructible_from>, min_impl>); -static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert(!std::constructible_from>, min_impl>); +static_assert(!std::convertible_to, quantity>>); -static_assert(!std::constructible_from>, min_impl>); -static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert(!std::constructible_from>, min_impl>); +static_assert(!std::convertible_to, quantity>>); // multiply syntax should work template concept creates_quantity = Unit && requires { T{} * U; }; -static_assert(creates_quantity, (si::metre)>); -static_assert(creates_quantity, (si::metre)>); +static_assert(creates_quantity, si::metre>); +static_assert(creates_quantity, si::metre>); // multiply syntax static_assert(creates_quantity, one>); @@ -99,47 +99,46 @@ static_assert(creates_quantity, percent>); // construction from a quantity // min_impl -> min_impl -static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>>); +static_assert(std::convertible_to>, quantity>>); -static_assert( - std::constructible_from>, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>>); +static_assert(std::convertible_to>, quantity>>); -static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>>); +static_assert(std::convertible_to>, quantity>>); -static_assert(!std::constructible_from>, - quantity<(si::metre), min_impl>>); // narrowing conversion -static_assert(!std::convertible_to>, quantity<(si::metre), min_impl>>); +static_assert(!std::constructible_from>, + quantity>>); // narrowing conversion +static_assert(!std::convertible_to>, quantity>>); // T -> min_impl -static_assert(std::constructible_from>, quantity<(si::metre), int>>); -static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>); +static_assert(std::convertible_to, quantity>>); -static_assert(std::constructible_from>, quantity<(si::metre), double>>); -static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>); +static_assert(std::convertible_to, quantity>>); -static_assert(std::constructible_from>, quantity<(si::metre), int>>); -static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>); +static_assert(std::convertible_to, quantity>>); -static_assert(!std::constructible_from>, - quantity<(si::metre), double>>); // narrowing conversion -static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert( + !std::constructible_from>, quantity>); // narrowing conversion +static_assert(!std::convertible_to, quantity>>); // min_impl -> T -static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), int>>); +static_assert(std::constructible_from, quantity>>); +static_assert(std::convertible_to>, quantity>); -static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), double>>); +static_assert(std::constructible_from, quantity>>); +static_assert(std::convertible_to>, quantity>); -static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), double>>); +static_assert(std::constructible_from, quantity>>); +static_assert(std::convertible_to>, quantity>); -static_assert(!std::constructible_from, - quantity<(si::metre), min_impl>>); // narrowing conversion -static_assert(!std::convertible_to>, quantity<(si::metre), int>>); +static_assert( + !std::constructible_from, quantity>>); // narrowing conversion +static_assert(!std::convertible_to>, quantity>); // arithmetic operators diff --git a/test/static/dimension_test.cpp b/test/static/dimension_test.cpp index f1d64590..8064831e 100644 --- a/test/static/dimension_test.cpp +++ b/test/static/dimension_test.cpp @@ -33,7 +33,7 @@ namespace { using namespace mp_units; -using dimension_one_ = struct mp_units::dimension_one; +using dimension_one_ = struct dimension_one; // clang-format off inline constexpr struct length_ final : base_dimension<"L"> {} length; diff --git a/test/static/quantity_point_test.cpp b/test/static/quantity_point_test.cpp index 941f638b..06ad1f16 100644 --- a/test/static/quantity_point_test.cpp +++ b/test/static/quantity_point_test.cpp @@ -58,24 +58,24 @@ inline constexpr struct mean_sea_level final : absolute_point_origin { +inline constexpr struct same_mean_sea_level final : relative_point_origin { } same_mean_sea_level; -inline constexpr struct ground_level final : relative_point_origin { +inline constexpr struct ground_level final : relative_point_origin { } ground_level; inline constexpr auto my_ground_level = ground_level; -inline constexpr struct same_ground_level1 final : relative_point_origin { +inline constexpr struct same_ground_level1 final : relative_point_origin { } same_ground_level1; -inline constexpr struct same_ground_level2 final : relative_point_origin { +inline constexpr struct same_ground_level2 final : relative_point_origin { } same_ground_level2; -inline constexpr struct tower_peak final : relative_point_origin { +inline constexpr struct tower_peak final : relative_point_origin { } tower_peak; -inline constexpr struct other_ground_level final : relative_point_origin { +inline constexpr struct other_ground_level final : relative_point_origin { } other_ground_level; inline constexpr struct other_absolute_level final : absolute_point_origin { @@ -152,10 +152,10 @@ static_assert(zeroth_point_origin != zeroth_point_origin) == sizeof(double)); -static_assert(sizeof(quantity_point<(isq::height[m]), mean_sea_level>) == sizeof(double)); -static_assert(sizeof(quantity_point<(si::metre), ground_level, short>) == sizeof(short)); -static_assert(sizeof(quantity_point<(isq::height[m]), ground_level, short>) == sizeof(short)); +static_assert(sizeof(quantity_point) == sizeof(double)); +static_assert(sizeof(quantity_point) == sizeof(double)); +static_assert(sizeof(quantity_point) == sizeof(short)); +static_assert(sizeof(quantity_point) == sizeof(short)); template typename QP> concept invalid_types = requires { @@ -188,15 +188,15 @@ static_assert(invalid_types); template typename QP> concept valid_types = requires { - typename QP<(si::metre), mean_sea_level, int>; - typename QP<(isq::height[m]), mean_sea_level, int>; - typename QP<(special_height[m]), mean_sea_level, int>; - typename QP<(si::metre), ground_level, int>; - typename QP<(isq::height[m]), ground_level, int>; - typename QP<(special_height[m]), ground_level, int>; - typename QP<(isq::height[m]), zeroth_point_origin<(isq::length)>, int>; - typename QP<(isq::height[m]), zeroth_point_origin>, int>; - typename QP<(si::metre), zeroth_point_origin<(isq::height)>, int>; + typename QP; + typename QP; + typename QP; + typename QP; + typename QP; + typename QP; + typename QP, int>; + typename QP>, int>; + typename QP, int>; }; static_assert(valid_types); @@ -217,14 +217,14 @@ static_assert(std::is_nothrow_destructible_v>); static_assert(std::is_standard_layout_v>); -static_assert(std::default_initializable>); -static_assert(std::move_constructible>); -static_assert(std::copy_constructible>); -static_assert(std::equality_comparable>); -static_assert(std::totally_ordered>); -static_assert(std::regular>); +static_assert(std::default_initializable>); +static_assert(std::move_constructible>); +static_assert(std::copy_constructible>); +static_assert(std::equality_comparable>); +static_assert(std::totally_ordered>); +static_assert(std::regular>); -static_assert(std::three_way_comparable>); +static_assert(std::three_way_comparable>); ////////////////// @@ -235,53 +235,51 @@ static_assert(quantity_point::reference == si::metre); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, zeroth_point_origin_>>); -static_assert( - is_of_type::absolute_point_origin, zeroth_point_origin_>>); +static_assert(is_of_type::point_origin, zeroth_point_origin_>>); +static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, zeroth_point_origin_>); -static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>); +static_assert(is_of_type::point_origin, zeroth_point_origin_>); +static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>); static_assert(quantity_point::reference == si::metre); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct mean_sea_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct mean_sea_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct mean_sea_level>); -static_assert( - is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct mean_sea_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct ground_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct ground_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct tower_peak>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct tower_peak>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == si::kelvin); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, struct si::absolute_zero>); +static_assert(is_of_type::point_origin, struct si::absolute_zero>); static_assert( - is_of_type::absolute_point_origin, struct si::absolute_zero>); + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == isq::thermodynamic_temperature[si::kelvin]); @@ -290,11 +288,10 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); +static_assert(is_of_type::point_origin, + struct si::absolute_zero>); static_assert( - is_of_type::point_origin, - struct si::absolute_zero>); -static_assert( - is_of_type::absolute_point_origin, + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == @@ -304,20 +301,19 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, +static_assert(is_of_type::point_origin, + struct si::absolute_zero>); +static_assert(is_of_type::absolute_point_origin, struct si::absolute_zero>); -static_assert( - is_of_type::absolute_point_origin, - struct si::absolute_zero>); static_assert(quantity_point::reference == si::degree_Celsius); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::degree_Celsius); -static_assert(is_of_type::point_origin, struct si::ice_point>); +static_assert(is_of_type::point_origin, struct si::ice_point>); static_assert( - is_of_type::absolute_point_origin, struct si::absolute_zero>); + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == isq::Celsius_temperature[si::degree_Celsius]); @@ -326,10 +322,10 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::degree_Celsius); -static_assert(is_of_type::point_origin, +static_assert(is_of_type::point_origin, struct si::ice_point>); static_assert( - is_of_type::absolute_point_origin, + is_of_type::absolute_point_origin, struct si::absolute_zero>); @@ -337,18 +333,18 @@ static_assert( // member types ////////////////// -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, int>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, int>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, int>); +static_assert(is_same_v::rep, int>); static_assert( - is_same_v::quantity_type, quantity>); + is_same_v::quantity_type, quantity>); //////////////////////////// @@ -375,11 +371,11 @@ static_assert( ////////////////////////////// // there is no construction from a value -static_assert(!std::constructible_from, double>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, double>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, int>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, int>); +static_assert(!std::convertible_to>); static_assert(!std::constructible_from, double>); static_assert(!std::convertible_to>); @@ -400,135 +396,135 @@ static_assert(!std::convertible_to, quantity<(si::metre)>>); -static_assert(!std::convertible_to, quantity_point<(si::metre)>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(si::metre)>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(si::metre)>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(isq::speed[m / s])>>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(isq::speed[m / s])>>); -static_assert(!std::convertible_to, quantity_point<(isq::length[m] / isq::time[s])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(isq::length[m] / isq::time[s])>>); -static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); static_assert(std::constructible_from, quantity>); static_assert(!std::convertible_to, quantity_point>); // different dimensions -static_assert(!std::constructible_from, quantity<(si::second)>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // convertible but different quantity_specs -static_assert(std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::length[m])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(special_height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::width[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::width[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity<(isq::length[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); #if MP_UNITS_HOSTED // quantity-like -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); #endif // ---------------------- // explicit point origins // ---------------------- -static_assert(!std::constructible_from, quantity<(si::metre)>>); -static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(si::metre)>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); static_assert(!std::constructible_from, quantity>); static_assert(!std::convertible_to, quantity_point>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::width[m]), zeroth_length>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::width[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), zeroth_length>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // different dimensions -static_assert(!std::constructible_from, quantity<(si::second)>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity<(isq::length[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // not-compatible origin -static_assert(!std::constructible_from, quantity<(isq::length[m])>>); -static_assert(!std::convertible_to, quantity_point<((si::metre)), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); #if MP_UNITS_HOSTED // quantity-like -static_assert(!std::constructible_from>, +static_assert(!std::constructible_from>, std::chrono::seconds>); static_assert(!std::convertible_to>>); + quantity_point>>); -static_assert(!std::constructible_from>, +static_assert(!std::constructible_from>, std::chrono::seconds>); static_assert(!std::convertible_to>>); + quantity_point>>); static_assert( - !std::constructible_from>, + !std::constructible_from>, std::chrono::seconds>); static_assert( !std::convertible_to>>); + quantity_point>>); #endif @@ -537,146 +533,140 @@ static_assert( /////////////////////////////////////// // implicit origin -static_assert(std::constructible_from, quantity_point<(si::metre)>>); -static_assert(std::convertible_to, quantity_point<(si::metre)>>); -static_assert(std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(std::convertible_to, quantity_point<(si::metre)>>); -static_assert(std::constructible_from, quantity_point<(si::metre)>>); -static_assert(std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(isq::speed[m / s])>>); -static_assert( - std::convertible_to, quantity_point<(isq::length[m]) / isq::time[s]>>); + std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point<(isq::speed[m / s])>>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point<(isq::length[m]) / isq::time[s]>>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); // convertible but different quantity_specs -static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::length[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::width[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point<(isq::width[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity_point<(isq::length[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // mixed origins -static_assert(!std::constructible_from, quantity_point<(si::metre)>>); -static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert( - !std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); -static_assert(!std::convertible_to, quantity_point<(si::metre)>>); -static_assert( - !std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // same explicit origins static_assert( - std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); + std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[km]), mean_sea_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[km]), mean_sea_level>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point>); static_assert( - std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, - quantity_point<(si::metre), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point>); static_assert( - std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, +static_assert(std::constructible_from, + quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert( + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert( + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert(std::constructible_from, quantity_point>); static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); + quantity_point>); static_assert( - std::constructible_from, quantity_point<(si::metre), ground_level>>); -static_assert( - std::convertible_to, quantity_point<(si::metre), ground_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), ground_level>>); -static_assert( - std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[km]), mean_sea_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[km]), ground_level>>); -static_assert( - std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); + std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(isq::height[m]), ground_level>>); + std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point<(si::metre), ground_level>>); + std::convertible_to, quantity_point>); + +static_assert(std::constructible_from, + quantity_point>); +static_assert( + std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(si::metre), ground_level>>); + std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, +static_assert( + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert( + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert(std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); + std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(si::metre), ground_level>>); -static_assert( - std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); + std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); -static_assert( - std::convertible_to, quantity_point<(si::metre), ground_level>>); + std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(si::metre), other_ground_level>>); + std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point<(si::metre), ground_level>>); + std::convertible_to, quantity_point>); static_assert( std::constructible_from, quantity_point>); @@ -692,121 +682,121 @@ static_assert( static_assert( std::convertible_to, quantity_point>); -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), zeroth_length>>); -static_assert(std::convertible_to, - quantity_point<(isq::length[m]), zeroth_length>>); +static_assert(std::constructible_from, + quantity_point>); +static_assert( + std::convertible_to, quantity_point>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), zeroth_length>>); -static_assert(!std::convertible_to, - quantity_point<(isq::width[m]), zeroth_length>>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert( + !std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, - quantity_point<(isq::width[m]), zeroth_length>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), zeroth_length>>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert( + !std::convertible_to, quantity_point>); // different dimensions -static_assert(!std::constructible_from, - quantity_point<(si::kelvin), (si::ice_point)>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert( + !std::constructible_from, quantity_point>); +static_assert( + !std::convertible_to, quantity_point>); // non-convertible quantity_specs static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::convertible_to, + quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // implicit conversion from another quantity point only if non-truncating // int -> double OK -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level, int>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point>); +static_assert(std::convertible_to, + quantity_point>); // truncating double -> int not allowed -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level, int>>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert(!std::convertible_to, + quantity_point>); // kilometre -> metre OK -static_assert(std::constructible_from, - quantity_point<(isq::height[km]), mean_sea_level, int>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level, int>>); +static_assert(std::constructible_from, + quantity_point>); +static_assert(std::convertible_to, + quantity_point>); // truncating metre -> kilometre not allowed -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level, int>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[km]), mean_sea_level, int>>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert(!std::convertible_to, + quantity_point>); // converting to double always OK -static_assert(std::constructible_from, - quantity_point<(isq::height[km]), mean_sea_level, int>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level, int>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[km]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point>); +static_assert(std::convertible_to, + quantity_point>); +static_assert(std::constructible_from, + quantity_point>); +static_assert(std::convertible_to, + quantity_point>); // same but not a default origin -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point>); static_assert( - std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, - quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, +static_assert( + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert(std::constructible_from, quantity_point>); static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); + quantity_point>); static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::convertible_to, + quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // different origins -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), other_absolute_level>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), other_absolute_level>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), ground_level>>); -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), ground_level>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), other_absolute_level>>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert(!std::convertible_to, + quantity_point>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert(!std::convertible_to, + quantity_point>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert(!std::convertible_to, + quantity_point>); #if MP_UNITS_HOSTED // quantity-point-like static_assert( - std::constructible_from>, sys_seconds>); + std::constructible_from>, sys_seconds>); static_assert( - std::convertible_to>>); + std::convertible_to>>); // incompatible origin -static_assert(!std::constructible_from>, - sys_seconds>); static_assert( - !std::convertible_to>>); + !std::constructible_from>, sys_seconds>); +static_assert( + !std::convertible_to>>); #endif @@ -835,19 +825,17 @@ static_assert((mean_sea_level + 42 * m).quantity_from(mean_sea_level) == 42 * m) static_assert((ground_level + 42 * m).quantity_from(ground_level) == 42 * m); static_assert((tower_peak + 42 * m).quantity_from(tower_peak) == 42 * m); -static_assert(quantity_point<(isq::height[m]), mean_sea_level>(ground_level + 42 * m).quantity_from(mean_sea_level) == +static_assert(quantity_point(ground_level + 42 * m).quantity_from(mean_sea_level) == 84 * m); -static_assert(quantity_point<(isq::height[m]), mean_sea_level>(tower_peak + 42 * m).quantity_from(mean_sea_level) == +static_assert(quantity_point(tower_peak + 42 * m).quantity_from(mean_sea_level) == 126 * m); -static_assert(quantity_point<(isq::height[m]), ground_level>(mean_sea_level + 84 * m).quantity_from(ground_level) == +static_assert(quantity_point(mean_sea_level + 84 * m).quantity_from(ground_level) == 42 * m); -static_assert(quantity_point<(isq::height[m]), ground_level>(tower_peak + 42 * m).quantity_from(ground_level) == - 84 * m); +static_assert(quantity_point(tower_peak + 42 * m).quantity_from(ground_level) == 84 * m); -static_assert(quantity_point<(isq::height[m]), tower_peak>(mean_sea_level + 42 * m).quantity_from(tower_peak) == - -42 * m); -static_assert(quantity_point<(isq::height[m]), tower_peak>(ground_level + 84 * m).quantity_from(tower_peak) == 42 * m); +static_assert(quantity_point(mean_sea_level + 42 * m).quantity_from(tower_peak) == -42 * m); +static_assert(quantity_point(ground_level + 84 * m).quantity_from(tower_peak) == 42 * m); static_assert((mean_sea_level + 42 * m).point_for(mean_sea_level).quantity_from(mean_sea_level) == 42 * m); static_assert((ground_level + 42 * m).point_for(mean_sea_level).quantity_from(mean_sea_level) == 84 * m); @@ -862,7 +850,7 @@ static_assert((mean_sea_level + 42 * m).point_for(tower_peak).quantity_from(towe static_assert((ground_level + 84 * m).point_for(tower_peak).quantity_from(tower_peak) == 42 * m); static_assert(is_of_type<(ground_level + isq::height(short{42} * m)).point_for(mean_sea_level), - quantity_point<(isq::height[m]), mean_sea_level, int>>); + quantity_point>); /////////////////////////////////// @@ -889,8 +877,8 @@ static_assert(is_of_type<(mean_sea_level + 2500. * m).force_in(km), quantit template typename QP> concept invalid_unit_conversion = requires { - requires !requires { QP<(isq::height[m]), mean_sea_level, int>(2000 * m).in(km); }; // truncating conversion - requires !requires { QP<(isq::height[m]), mean_sea_level, int>(2 * m).in(s); }; // invalid unit + requires !requires { QP(2000 * m).in(km); }; // truncating conversion + requires !requires { QP(2 * m).in(s); }; // invalid unit }; static_assert(invalid_unit_conversion); @@ -938,12 +926,13 @@ static_assert(quantity_point{sys_seconds{24h}}.quantity_spec == kind_of typename QP> concept invalid_compound_assignments = requires() { // truncating not allowed - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += 2.5 * m; }; - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= 2.5 * m; }; - requires !requires(QP l) { l += 2 * (isq::height[m]); }; - requires !requires(QP l) { l -= 2 * (isq::height[m]); }; + requires !requires(QP l) { l += 2.5 * m; }; + requires !requires(QP l) { l -= 2.5 * m; }; + requires !requires(QP l) { l += 2 * isq::height[m]; }; + requires !requires(QP l) { l -= 2 * isq::height[m]; }; // only quantities can be added or subtracted - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += 2; }; - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= 2; }; + requires !requires(QP l) { l += 2; }; + requires !requires(QP l) { l -= 2; }; // no unit constants - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += m; }; - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= m; }; + requires !requires(QP l) { l += m; }; + requires !requires(QP l) { l -= m; }; }; static_assert(invalid_compound_assignments); @@ -1143,12 +1132,12 @@ concept invalid_binary_operations = requires { requires !requires { Origin - Origin; }; // unit constants - requires !requires { QP<(si::metre), mean_sea_level, int>(1) + m; }; - requires !requires { QP<(si::metre), mean_sea_level, int>(1) - m; }; + requires !requires { QP(1) + m; }; + requires !requires { QP(1) - m; }; requires !requires { Origin + m; }; requires !requires { Origin - m; }; - requires !requires { m + QP<(si::metre), mean_sea_level, int>(1); }; - requires !requires { m - QP<(si::metre), mean_sea_level, int>(1); }; + requires !requires { m + QP(1); }; + requires !requires { m - QP(1); }; requires !requires { m + Origin; }; requires !requires { m - Origin; }; }; @@ -1185,36 +1174,36 @@ static_assert(is_of_type<1 * m + (mean_sea_level + 1 * km), quantity_point>); static_assert( - is_of_type<1 * m + (mean_sea_level + isq::height(1 * m)), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<1 * m + (mean_sea_level + isq::height(1 * m)), quantity_point>); static_assert( - is_of_type<1 * m + (mean_sea_level + isq::height(1 * km)), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<1 * m + (mean_sea_level + isq::height(1 * km)), quantity_point>); static_assert( - is_of_type<1 * km + (mean_sea_level + isq::height(1 * m)), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<1 * km + (mean_sea_level + isq::height(1 * m)), quantity_point>); static_assert( - is_of_type>); + is_of_type>); static_assert( - is_of_type>); + is_of_type>); static_assert( - is_of_type>); + is_of_type>); static_assert(is_of_type>); + quantity_point>); static_assert(is_of_type>); + quantity_point>); static_assert(is_of_type>); + quantity_point>); static_assert(is_of_type>); static_assert(is_of_type, mean_sea_level, int>>); -static_assert(is_of_type>); +static_assert(is_of_type>); static_assert( is_of_type>); static_assert(is_of_type], mean_sea_level, int>>); static_assert(is_of_type<1 * m + mean_sea_level, quantity_point>); static_assert(is_of_type<1 * km + mean_sea_level, quantity_point, mean_sea_level, int>>); -static_assert(is_of_type>); +static_assert(is_of_type>); static_assert( is_of_type>); static_assert(is_of_type>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * m), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * m), quantity_point>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * km), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * km), quantity_point>); static_assert( - is_of_type<(mean_sea_level + 1 * km) - isq::height(1 * m), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + 1 * km) - isq::height(1 * m), quantity_point>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * m, quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * m, quantity_point>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * km, quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * km, quantity_point>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * km)) - 1 * m, quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + isq::height(1 * km)) - 1 * m, quantity_point>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - isq::height(1 * m), - quantity_point<(isq::height[m]), mean_sea_level, int>>); + quantity_point>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - isq::height(1 * km), - quantity_point<(isq::height[m]), mean_sea_level, int>>); + quantity_point>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * km)) - isq::height(1 * m), - quantity_point<(isq::height[m]), mean_sea_level, int>>); + quantity_point>); static_assert(is_of_type>); static_assert(is_of_type, mean_sea_level, int>>); @@ -1265,39 +1254,39 @@ static_assert(is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + 1 * m), q static_assert(is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + 1 * km), quantity>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * m)), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * m)), quantity>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * km)), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * km)), quantity>); static_assert( - is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + isq::height(1 * m)), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + isq::height(1 * m)), quantity>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * m), quantity>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * km), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * km), quantity>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + 1 * m), quantity>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + isq::height(1 * m)), - quantity<(isq::height[m]), int>>); + quantity>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + isq::height(1 * km)), - quantity<(isq::height[m]), int>>); + quantity>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + isq::height(1 * m)), - quantity<(isq::height[m]), int>>); + quantity>); static_assert(is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + 1 * m), quantity>); static_assert(is_of_type<(ground_level + 1 * m) - (ground_level + 1 * m), quantity>); static_assert(is_of_type<(tower_peak + 1 * m) - (tower_peak + 1 * m), quantity>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(ground_level + 1 * m) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(tower_peak + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(ground_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(tower_peak + 1 * m) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(other_ground_level + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(ground_level + 1 * m) - (other_ground_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(other_ground_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(tower_peak + 1 * m) - (other_ground_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - (ground_level + 1 * m), quantity>); +static_assert(is_of_type<(ground_level + 1 * m) - (mean_sea_level + 1 * m), quantity>); +static_assert(is_of_type<(tower_peak + 1 * m) - (ground_level + 1 * m), quantity>); +static_assert(is_of_type<(ground_level + 1 * m) - (tower_peak + 1 * m), quantity>); +static_assert(is_of_type<(tower_peak + 1 * m) - (mean_sea_level + 1 * m), quantity>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - (tower_peak + 1 * m), quantity>); +static_assert(is_of_type<(other_ground_level + 1 * m) - (ground_level + 1 * m), quantity>); +static_assert(is_of_type<(ground_level + 1 * m) - (other_ground_level + 1 * m), quantity>); +static_assert(is_of_type<(other_ground_level + 1 * m) - (tower_peak + 1 * m), quantity>); +static_assert(is_of_type<(tower_peak + 1 * m) - (other_ground_level + 1 * m), quantity>); static_assert(is_of_type>); static_assert(is_of_type, int>>); @@ -1309,32 +1298,32 @@ static_assert(is_of_type>); static_assert(is_of_type<(ground_level + 1 * km) - ground_level, quantity, int>>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type<(ground_level + 1 * m) - mean_sea_level, quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(ground_level + 1 * km) - mean_sea_level, quantity<(isq::height[m]), int>>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type<(ground_level + 1 * m) - mean_sea_level, quantity>); +static_assert(is_of_type<(ground_level + 1 * km) - mean_sea_level, quantity>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - ground_level, quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(mean_sea_level + 1 * km) - ground_level, quantity<(isq::height[m]), int>>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - ground_level, quantity>); +static_assert(is_of_type<(mean_sea_level + 1 * km) - ground_level, quantity>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); -static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + mean_sea_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + mean_sea_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + other_ground_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + other_ground_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + ground_level), quantity>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + mean_sea_level), quantity>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + ground_level), quantity>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + tower_peak), quantity>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + mean_sea_level), quantity>); +static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + tower_peak), quantity>); +static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + ground_level), quantity>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + other_ground_level), quantity>); +static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + tower_peak), quantity>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + other_ground_level), quantity>); // check for integral types promotion @@ -1654,8 +1643,8 @@ static_assert(is_of_type<(zero_Hz + 5 * isq::frequency[Hz]) - (zero_Hz + 10 / (2 static_assert((quantity_point{10 / (2 * isq::period_duration[s])} + 5 * isq::frequency[Hz]).quantity_from_zero() == 10 * isq::frequency[Hz]); -static_assert((10 / (2 * isq::period_duration[s]) + (zero_Hz + 5 * isq::frequency[Hz])).quantity_from_zero() == - 10 * isq::frequency[Hz]); +static_assert((10 / (2 * isq::period_duration[s]) + quantity_point{zero_Hz + 5 * isq::frequency[Hz]}) + .quantity_from_zero() == 10 * isq::frequency[Hz]); static_assert((quantity_point{5 * isq::frequency[Hz]} + 10 / (2 * isq::period_duration[s])).quantity_from_zero() == 10 * isq::frequency[Hz]); static_assert((5 * isq::frequency[Hz] + quantity_point{10 / (2 * isq::period_duration[s])}).quantity_from_zero() == @@ -1729,7 +1718,7 @@ static_assert(value_cast(quantity_point{2 * km}).quantity_from_zero().numeric static_assert(value_cast(quantity_point{2000 * m}).quantity_from_zero().numerical_value_in(km) == 2); static_assert(value_cast(quantity_point{1.23 * m}).quantity_from_zero().numerical_value_in(m) == 1); static_assert( - value_cast<(km / h)>(quantity_point{2000.0 * m / (3600.0 * s)}).quantity_from_zero().numerical_value_in(km / h) == 2); + value_cast(quantity_point{2000.0 * m / (3600.0 * s)}).quantity_from_zero().numerical_value_in(km / h) == 2); // lvalue references in value_cast namespace lvalue_tests { constexpr quantity_point lvalue_qp{2 * km}; diff --git a/test/static/quantity_spec_test.cpp b/test/static/quantity_spec_test.cpp index ed4cb359..ee4e86a8 100644 --- a/test/static/quantity_spec_test.cpp +++ b/test/static/quantity_spec_test.cpp @@ -33,8 +33,8 @@ namespace { using namespace mp_units; -using dimensionless_ = struct mp_units::dimensionless; -using dim_one_ = struct mp_units::dimension_one; +using dimensionless_ = struct dimensionless; +using dim_one_ = struct dimension_one; // clang-format off inline constexpr struct dim_length_ final : base_dimension<"L"> {} dim_length; diff --git a/test/static/quantity_test.cpp b/test/static/quantity_test.cpp index 3167b018..d8ddfe60 100644 --- a/test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -84,14 +84,14 @@ static_assert(std::is_nothrow_destructible_v>); static_assert(std::is_trivially_copyable_v>); static_assert(std::is_standard_layout_v>); -static_assert(std::default_initializable>); -static_assert(std::move_constructible>); -static_assert(std::copy_constructible>); -static_assert(std::equality_comparable>); -static_assert(std::totally_ordered>); -static_assert(std::regular>); +static_assert(std::default_initializable>); +static_assert(std::move_constructible>); +static_assert(std::copy_constructible>); +static_assert(std::equality_comparable>); +static_assert(std::totally_ordered>); +static_assert(std::regular>); -static_assert(std::three_way_comparable>); +static_assert(std::three_way_comparable>); ////////////////// @@ -112,8 +112,8 @@ static_assert(quantity::unit == si::metre); // member types ///////////////// -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::rep, int>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::rep, int>); //////////////////////////// @@ -135,11 +135,11 @@ static_assert(quantity::max().numerical_value_in(m) == s ///////////////////////////////////////////////// // construction from a value is private -static_assert(!std::constructible_from, double>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, double>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, int>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, int>); +static_assert(!std::convertible_to>); static_assert(std::constructible_from, double>); static_assert(std::convertible_to>); @@ -159,46 +159,45 @@ static_assert(std::convertible_to>); /////////////////////////////////////// // conversion only between convertible quantities -static_assert(std::constructible_from, quantity<(isq::length[m])>>); -static_assert(std::convertible_to, quantity<(isq::length[m])>>); -static_assert(std::constructible_from, quantity<(isq::distance[m])>>); -static_assert(std::convertible_to, quantity<(isq::length[m])>>); -static_assert(std::constructible_from, quantity<(isq::length[km])>>); -static_assert(std::convertible_to, quantity<(isq::length[m])>>); +static_assert(std::constructible_from, quantity>); +static_assert(std::convertible_to, quantity>); +static_assert(std::constructible_from, quantity>); +static_assert(std::convertible_to, quantity>); +static_assert(std::constructible_from, quantity>); +static_assert(std::convertible_to, quantity>); // conversion between different quantities not allowed -static_assert(!std::constructible_from, quantity<(isq::time[s])>>); -static_assert(!std::convertible_to, quantity<(isq::length[m])>>); -static_assert(!std::constructible_from, quantity<(isq::speed[m / s])>>); -static_assert(!std::convertible_to, quantity<(isq::length[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity>); // implicit conversion from another quantity only if non-truncating +static_assert(std::constructible_from, quantity>); // int -> double OK +static_assert(std::convertible_to, quantity>); // int -> double OK + +static_assert(!std::constructible_from, + quantity>); // truncating double -> int not allowed +static_assert(!std::convertible_to, + quantity>); // truncating double -> int not allowed + +static_assert(std::constructible_from, + quantity>); // kilometre -> metre OK +static_assert(std::convertible_to, + quantity>); // kilometre -> metre OK + +static_assert(!std::constructible_from, + quantity>); // truncating metre -> + // kilometre not allowed static_assert( - std::constructible_from, quantity<(isq::length[m]), int>>); // int -> double OK -static_assert(std::convertible_to, quantity<(isq::length[m])>>); // int -> double OK - -static_assert(!std::constructible_from, - quantity<(isq::length[m])>>); // truncating double -> int not allowed -static_assert(!std::convertible_to, - quantity<(isq::length[m]), int>>); // truncating double -> int not allowed - -static_assert(std::constructible_from, - quantity<(isq::length[km]), int>>); // kilometre -> metre OK -static_assert(std::convertible_to, - quantity<(isq::length[m]), int>>); // kilometre -> metre OK - -static_assert(!std::constructible_from, - quantity<(isq::length[m]), int>>); // truncating metre -> - // kilometre not allowed -static_assert( - !std::convertible_to, - quantity<(isq::length[km]), int>>); // truncating metre -> kilometre not allowed + !std::convertible_to, + quantity>); // truncating metre -> kilometre not allowed // converting to double always OK -static_assert(std::constructible_from, quantity<(isq::length[km]), int>>); -static_assert(std::convertible_to, quantity<(isq::length[m])>>); -static_assert(std::constructible_from, quantity<(isq::length[m]), int>>); -static_assert(std::convertible_to, quantity<(isq::length[km])>>); +static_assert(std::constructible_from, quantity>); +static_assert(std::convertible_to, quantity>); +static_assert(std::constructible_from, quantity>); +static_assert(std::convertible_to, quantity>); /////////////////////// // obtaining a number @@ -216,16 +215,16 @@ static_assert(quantity(1500 * m).numerical_value_in(km) == 1.5) static_assert(!std::convertible_to, double>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, double>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, double>); +static_assert(std::constructible_from>); static_assert(!std::convertible_to, int>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, int>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, int>); +static_assert(std::constructible_from>); static_assert(!std::convertible_to, double>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, double>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, double>); +static_assert(std::constructible_from>); /////////////////////////////////// @@ -312,9 +311,9 @@ struct derived_quantity : quantity { R::operator=(t); return *this; } - constexpr derived_quantity& operator=(R&& other) + constexpr derived_quantity& operator=(R&& t) { - R::operator=(std::move(other)); + R::operator=(std::move(t)); return *this; } // NOLINTBEGIN(google-explicit-constructor, hicpp-explicit-conversions) @@ -325,9 +324,9 @@ struct derived_quantity : quantity { // NOLINTEND(google-explicit-constructor, hicpp-explicit-conversions) }; -static_assert(Quantity, "NTTP type description">>); +static_assert(Quantity, "NTTP type description">>); -constexpr QuantityOf<(isq::length)> auto get_length_derived_quantity() noexcept +constexpr QuantityOf auto get_length_derived_quantity() noexcept { derived_quantity, "NTTP type description"> dist{}; dist += 1 * m; @@ -356,8 +355,7 @@ static_assert(quantity{123}.quantity_spec == kind_of); #if MP_UNITS_HOSTED using namespace std::chrono_literals; static_assert(std::is_same_v); -// return type for "s" is not specified. is double for msvc -// static_assert(std::is_same_v); +static_assert(std::is_same_v); static_assert(quantity{24h}.unit == si::hour); static_assert(quantity{24h}.quantity_spec == kind_of); #endif @@ -456,10 +454,10 @@ static_assert((std::uint8_t{255}* m %= 257 * m).numerical_value_in(m) != [] { #if !(defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 18 && defined MP_UNITS_MODULES) // next two lines trigger conversions warnings // (warning disabled in CMake for this file) -static_assert(((22 * m) *= 33.33).numerical_value_in(m) == 733); -static_assert(((22 * m) /= 3.33).numerical_value_in(m) == 6); -static_assert(((22 * m) *= 33.33 * one).numerical_value_in(m) == 733); -static_assert(((22 * m) /= 3.33 * one).numerical_value_in(m) == 6); +static_assert((22 * m *= 33.33).numerical_value_in(m) == 733); +static_assert((22 * m /= 3.33).numerical_value_in(m) == 6); +static_assert((22 * m *= 33.33 * one).numerical_value_in(m) == 733); +static_assert((22 * m /= 3.33 * one).numerical_value_in(m) == 6); #endif template typename Q> @@ -845,30 +843,27 @@ static_assert(2 * one / (1 * m) == 2 / (1 * m)); // equality operators /////////////////////// -static_assert(std::equality_comparable_with, quantity<(si::metre)>>); -static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity<(si::metre)>>); -static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity>); static_assert( - std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity<(si::metre)>>); -static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); -static_assert( - std::equality_comparable_with, quantity<(si::kilo<(si::metre)>), int>>); -static_assert(std::equality_comparable_with, quantity<(isq::height[(si::metre)])>>); -static_assert( - std::equality_comparable_with, quantity<(isq::height[(si::metre)]), int>>); -static_assert(std::equality_comparable_with, - quantity<(isq::height[(si::kilo<(si::metre)>)]), int>>); + std::equality_comparable_with, quantity], int>>); template concept no_crossdimensional_equality = requires { requires !requires { 1 * s == 1 * M; }; requires !requires { 1 * s != 1 * M; }; }; -static_assert(no_crossdimensional_equality<(si::metre)>); +static_assert(no_crossdimensional_equality); // same type static_assert(123 * m == 123 * m); @@ -921,7 +916,7 @@ concept no_crossdimensional_ordering = requires { requires !requires { 1 * s <= 1 * M; }; requires !requires { 1 * s >= 1 * M; }; }; -static_assert(no_crossdimensional_ordering<(si::metre)>); +static_assert(no_crossdimensional_ordering); // same type static_assert(123 * m < 321 * m); @@ -1035,35 +1030,34 @@ static_assert(is_of_type(lvalue_q), quantity, (isq::length)>); -static_assert(QuantityOf, (isq::length)>); -static_assert(QuantityOf, (isq::length)>); -static_assert(!QuantityOf, (isq::width)>); -static_assert(QuantityOf, (isq::width)>); -static_assert(QuantityOf, (isq::position_vector)>); -static_assert(QuantityOf[m]>, (isq::width)>); -static_assert(QuantityOf[m]>, (isq::position_vector)>); -static_assert(!QuantityOf, isq::altitude>); +static_assert(QuantityOf, isq::length>); +static_assert(QuantityOf, isq::length>); +static_assert(QuantityOf, isq::length>); +static_assert(!QuantityOf, isq::width>); +static_assert(QuantityOf, isq::width>); +static_assert(QuantityOf, isq::position_vector>); +static_assert(QuantityOf[m]>, isq::width>); +static_assert(QuantityOf[m]>, isq::position_vector>); +static_assert(!QuantityOf, isq::altitude>); -static_assert(QuantityOf, (isq::speed)>); -static_assert(QuantityOf, (isq::length) / (isq::time)>); +static_assert(QuantityOf, isq::speed>); +static_assert(QuantityOf, isq::length / isq::time>); static_assert(QuantityOf, isq::length / isq::time>); -static_assert(QuantityOf[m / s]>, (isq::length) / (isq::time)>); -static_assert(!QuantityOf, (isq::distance) / (isq::duration)>); -static_assert(!QuantityOf, (isq::width) / (isq::duration)>); +static_assert(QuantityOf[m / s]>, isq::length / isq::time>); +static_assert(!QuantityOf, isq::distance / isq::duration>); +static_assert(!QuantityOf, isq::width / isq::duration>); static_assert(QuantityOf, isq::width / isq::duration>); -static_assert(QuantityOf[m / s]>, (isq::width) / (isq::duration)>); -static_assert(!QuantityOf, (isq::position_vector) / (isq::duration)>); +static_assert(QuantityOf[m / s]>, isq::width / isq::duration>); +static_assert(!QuantityOf, isq::position_vector / isq::duration>); static_assert(QuantityOf, isq::position_vector / isq::duration>); -static_assert(QuantityOf[m / s]>, isq::position_vector / isq::duration>); -static_assert(QuantityOf, isq::position_vector / isq::duration>); +static_assert(QuantityOf[m / s]>, isq::position_vector / isq::duration>); +static_assert(QuantityOf, isq::position_vector / isq::duration>); -static_assert(QuantityOf); // kind of -static_assert(QuantityOf[m]), (isq::height)>); // kind of -static_assert(!QuantityOf); // different kinds -static_assert(!QuantityOf); // different kinds -static_assert(QuantityOf); -static_assert( - QuantityOf); // derived unnamed quantity +static_assert(QuantityOf); // kind of +static_assert(QuantityOf[m]), isq::height>); // kind of +static_assert(!QuantityOf); // different kinds +static_assert(!QuantityOf); // different kinds +static_assert(QuantityOf); +static_assert(QuantityOf); // derived unnamed quantity } // namespace diff --git a/test/static/reference_test.cpp b/test/static/reference_test.cpp index 46026702..65abe0bb 100644 --- a/test/static/reference_test.cpp +++ b/test/static/reference_test.cpp @@ -34,8 +34,8 @@ namespace { using namespace mp_units; -using dimensionless_ = struct mp_units::dimensionless; -using one_ = struct mp_units::one; +using dimensionless_ = struct dimensionless; +using one_ = struct one; // base dimensions // clang-format off @@ -238,7 +238,7 @@ template concept invalid_nu_unit = !requires { dim[unit]; }; static_assert(invalid_nu_unit); -static_assert(invalid_nu_unit<(nu::time), second>); +static_assert(invalid_nu_unit); static_assert(invalid_nu_unit); static_assert(invalid_nu_unit); static_assert(invalid_nu_unit); diff --git a/test/static/si_test.cpp b/test/static/si_test.cpp index d52a8edc..4f306fd2 100644 --- a/test/static/si_test.cpp +++ b/test/static/si_test.cpp @@ -65,7 +65,7 @@ concept can_not_be_prefixed = Unit && !requires { typename prefix< static_assert(can_not_be_prefixed); static_assert(can_not_be_prefixed); -static_assert(can_not_be_prefixed)>); +static_assert(can_not_be_prefixed>); static_assert(can_not_be_prefixed); static_assert(can_not_be_prefixed * si::degree>); diff --git a/test/static/unit_test.cpp b/test/static/unit_test.cpp index c16ea66a..ba7ecb4c 100644 --- a/test/static/unit_test.cpp +++ b/test/static/unit_test.cpp @@ -35,8 +35,8 @@ namespace { using namespace mp_units; using namespace mp_units::detail; -using one_ = struct mp_units::one; -using percent_ = struct mp_units::percent; +using one_ = struct one; +using percent_ = struct percent; // base dimensions // clang-format off From d1897b1fe95bdc040ee1e4e67b07d166fbea08e8 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:28:44 +0200 Subject: [PATCH 28/44] [PR] change disable error to macro --- src/core/include/mp-units/bits/fmt.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/core/include/mp-units/bits/fmt.h b/src/core/include/mp-units/bits/fmt.h index 3589bc11..084027f3 100644 --- a/src/core/include/mp-units/bits/fmt.h +++ b/src/core/include/mp-units/bits/fmt.h @@ -189,10 +189,8 @@ constexpr void handle_dynamic_spec(int& value, fmt_arg_ref [[nodiscard]] constexpr unsigned long long operator()(T value) const @@ -205,10 +203,7 @@ struct width_checker { MP_UNITS_THROW(MP_UNITS_STD_FMT::format_error("width is not integer")); } }; - -#ifdef _MSC_VER -#pragma warning(pop) -#endif +MP_UNITS_DIAGNOSTIC_POP MP_UNITS_EXPORT_END From d18bb28a251a3dbe922c5f99da219e038b169116 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:32:21 +0200 Subject: [PATCH 29/44] [PR] remove MP_UNITS_TYPENAME --- src/core/include/mp-units/bits/hacks.h | 2 - src/core/include/mp-units/bits/sudo_cast.h | 8 +- src/core/include/mp-units/bits/type_list.h | 26 +++---- src/core/include/mp-units/ext/type_traits.h | 12 +-- .../mp-units/framework/expression_template.h | 10 +-- src/core/include/mp-units/random.h | 78 +++++++++---------- .../include/mp-units/systems/si/chrono.h | 4 +- 7 files changed, 69 insertions(+), 71 deletions(-) diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 9dd88298..253738e3 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -79,7 +79,6 @@ #if MP_UNITS_COMP_MSVC -#define MP_UNITS_TYPENAME typename #define MP_UNITS_EXPRESSION(x) (x) #define MP_UNITS_IS_VALUE(x) (x) #define MP_UNITS_IS_CONST_EXPR(x) \ @@ -87,7 +86,6 @@ #else -#define MP_UNITS_TYPENAME #define MP_UNITS_EXPRESSION(x) x #define MP_UNITS_IS_VALUE(x) x #define MP_UNITS_IS_CONST_EXPR(x) x diff --git a/src/core/include/mp-units/bits/sudo_cast.h b/src/core/include/mp-units/bits/sudo_cast.h index 0873fd59..b96c3e34 100644 --- a/src/core/include/mp-units/bits/sudo_cast.h +++ b/src/core/include/mp-units/bits/sudo_cast.h @@ -46,7 +46,7 @@ template struct get_common_type : std::common_type {}; template -using maybe_common_type = MP_UNITS_TYPENAME +using maybe_common_type = std::conditional_t, get_common_type, std::type_identity>::type; /** @@ -108,7 +108,7 @@ template constexpr auto q_unit = std::remove_reference_t::unit; if constexpr (q_unit == To::unit) { // no scaling of the number needed - return {static_cast(std::forward(q).numerical_value_is_an_implementation_detail_), + return {static_cast< To::rep>(std::forward(q).numerical_value_is_an_implementation_detail_), To::reference}; // this is the only (and recommended) way to do a truncating conversion on a number, so we // are using static_cast to suppress all the compiler warnings on conversions } else { @@ -116,12 +116,12 @@ template using traits = magnitude_conversion_traits>; if constexpr (std::is_floating_point_v) { // this results in great assembly - auto res = static_cast( + auto res = static_cast< To::rep>( static_cast(q.numerical_value_is_an_implementation_detail_) * traits::ratio); return {res, To::reference}; } else { // this is slower but allows conversions like 2000 m -> 2 km without loosing data - auto res = static_cast( + auto res = static_cast< To::rep>( static_cast(q.numerical_value_is_an_implementation_detail_) * traits::num_mult / traits::den_mult * traits::irr_mult); return {res, To::reference}; diff --git a/src/core/include/mp-units/bits/type_list.h b/src/core/include/mp-units/bits/type_list.h index 203326c6..be9ea15c 100644 --- a/src/core/include/mp-units/bits/type_list.h +++ b/src/core/include/mp-units/bits/type_list.h @@ -68,7 +68,7 @@ struct type_list_map_impl, To> { }; template typename To> -using type_list_map = MP_UNITS_TYPENAME type_list_map_impl::type; +using type_list_map = type_list_map_impl::type; // element @@ -105,7 +105,7 @@ struct type_list_front_impl> { }; template -using type_list_front = MP_UNITS_TYPENAME type_list_front_impl::type; +using type_list_front = type_list_front_impl::type; // back template @@ -121,7 +121,7 @@ struct type_list_push_front_impl, NewTypes...> { }; template -using type_list_push_front = MP_UNITS_TYPENAME type_list_push_front_impl::type; +using type_list_push_front = type_list_push_front_impl::type; // push_back template @@ -133,7 +133,7 @@ struct type_list_push_back_impl, NewTypes...> { }; template -using type_list_push_back = MP_UNITS_TYPENAME type_list_push_back_impl::type; +using type_list_push_back = type_list_push_back_impl::type; // join template @@ -143,11 +143,11 @@ struct type_list_join_impl { template typename List, typename... First, typename... Second, typename... Rest> struct type_list_join_impl, List, Rest...> { - using type = MP_UNITS_TYPENAME type_list_join_impl, Rest...>::type; + using type = type_list_join_impl, Rest...>::type; }; template -using type_list_join = MP_UNITS_TYPENAME type_list_join_impl::type; +using type_list_join = type_list_join_impl::type; // split template @@ -195,19 +195,19 @@ template typename List, typename Lhs1, typename... LhsRest template typename Pred> requires Pred::value struct type_list_merge_sorted_impl, List, Pred> { - using type = MP_UNITS_TYPENAME type_list_push_front_impl< + using type = type_list_push_front_impl< typename type_list_merge_sorted_impl, List, Pred>::type, Lhs1>::type; }; template typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest, template typename Pred> struct type_list_merge_sorted_impl, List, Pred> { - using type = MP_UNITS_TYPENAME type_list_push_front_impl< + using type = type_list_push_front_impl< typename type_list_merge_sorted_impl, List, Pred>::type, Rhs1>::type; }; template typename Pred> -using type_list_merge_sorted = MP_UNITS_TYPENAME type_list_merge_sorted_impl::type; +using type_list_merge_sorted = type_list_merge_sorted_impl::type; // sort template typename Pred> @@ -227,13 +227,13 @@ template typename List, typename... Types, template, Pred> { using types = List; using split = type_list_split_half>; - using sorted_left = MP_UNITS_TYPENAME type_list_sort_impl::type; - using sorted_right = MP_UNITS_TYPENAME type_list_sort_impl::type; - using type = MP_UNITS_TYPENAME type_list_merge_sorted_impl::type; + using sorted_left = type_list_sort_impl::type; + using sorted_right = type_list_sort_impl::type; + using type = type_list_merge_sorted_impl::type; }; template typename Pred> -using type_list_sort = MP_UNITS_TYPENAME type_list_sort_impl::type; +using type_list_sort = type_list_sort_impl::type; } // namespace mp_units::detail diff --git a/src/core/include/mp-units/ext/type_traits.h b/src/core/include/mp-units/ext/type_traits.h index 62e39f09..1ffd715e 100644 --- a/src/core/include/mp-units/ext/type_traits.h +++ b/src/core/include/mp-units/ext/type_traits.h @@ -56,7 +56,7 @@ struct conditional_impl { MP_UNITS_EXPORT_BEGIN template -using conditional = MP_UNITS_TYPENAME detail::conditional_impl::template type; +using conditional = detail::conditional_impl::template type; // is_same template @@ -99,7 +99,7 @@ namespace detail { template struct get_value_type { - using type = MP_UNITS_TYPENAME T::value_type; + using type = T::value_type; }; template @@ -112,13 +112,13 @@ struct get_element_type { template requires requires { typename T::value_type; } || requires { typename T::element_type; } struct wrapped_type { - using type = MP_UNITS_TYPENAME + using type = conditional, detail::get_element_type>::type; }; template requires requires { typename T::value_type; } || requires { typename T::element_type; } -using wrapped_type_t = MP_UNITS_TYPENAME wrapped_type::type; +using wrapped_type_t = wrapped_type::type; template struct value_type { @@ -128,11 +128,11 @@ struct value_type { template requires requires { typename wrapped_type_t; } struct value_type { - using type = MP_UNITS_TYPENAME wrapped_type_t; + using type = wrapped_type_t; }; template -using value_type_t = MP_UNITS_TYPENAME value_type::type; +using value_type_t = value_type::type; template concept one_of = (false || ... || std::same_as); diff --git a/src/core/include/mp-units/framework/expression_template.h b/src/core/include/mp-units/framework/expression_template.h index 72a2db0e..2b607130 100644 --- a/src/core/include/mp-units/framework/expression_template.h +++ b/src/core/include/mp-units/framework/expression_template.h @@ -122,7 +122,7 @@ struct expr_type_impl> : std::type_identity {}; } // namespace detail template -using expr_type = MP_UNITS_TYPENAME detail::expr_type_impl::type; +using expr_type = detail::expr_type_impl::type; namespace detail { @@ -182,25 +182,25 @@ struct expr_consolidate_impl> { template requires(!is_specialization_of_power) struct expr_consolidate_impl> { - using type = MP_UNITS_TYPENAME expr_consolidate_impl, Rest...>>::type; + using type = expr_consolidate_impl, Rest...>>::type; }; // replaces the instance of a type and a power of it with one with incremented power template struct expr_consolidate_impl, Rest...>> { using type = - MP_UNITS_TYPENAME expr_consolidate_impl::exponent + 1>, Rest...>>::type; + expr_consolidate_impl::exponent + 1>, Rest...>>::type; }; // accumulates the powers of instances of the same type (removes the element in case the accumulation result is `0`) template struct expr_consolidate_impl, power, Rest...>> { static constexpr ratio r = power::exponent + power::exponent; - using type = MP_UNITS_TYPENAME expr_consolidate_impl, Rest...>>::type; + using type = expr_consolidate_impl, Rest...>>::type; }; template -using expr_consolidate = MP_UNITS_TYPENAME expr_consolidate_impl::type; +using expr_consolidate = expr_consolidate_impl::type; /** diff --git a/src/core/include/mp-units/random.h b/src/core/include/mp-units/random.h index a470c3b0..05251f3f 100644 --- a/src/core/include/mp-units/random.h +++ b/src/core/include/mp-units/random.h @@ -61,7 +61,7 @@ std::vector bl_qty_to_rep(std::initializer_list& bl) template std::vector fw_bl_pwc(std::initializer_list& bl, UnaryOperation fw) { - using rep = MP_UNITS_TYPENAME Q::rep; + using rep = Q::rep; std::vector w_bl; w_bl.reserve(bl.size()); for (const Q& qty : bl) { @@ -93,8 +93,8 @@ MP_UNITS_EXPORT_BEGIN template requires std::integral struct uniform_int_distribution : public std::uniform_int_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::uniform_int_distribution; + using rep = Q::rep; + using base = std::uniform_int_distribution; uniform_int_distribution() : base() {} uniform_int_distribution(const Q& a, const Q& b) : @@ -118,8 +118,8 @@ struct uniform_int_distribution : public std::uniform_int_distribution requires std::floating_point struct uniform_real_distribution : public std::uniform_real_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::uniform_real_distribution; + using rep = Q::rep; + using base = std::uniform_real_distribution; uniform_real_distribution() : base() {} uniform_real_distribution(const Q& a, const Q& b) : @@ -143,8 +143,8 @@ struct uniform_real_distribution : public std::uniform_real_distribution requires std::integral struct binomial_distribution : public std::binomial_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::binomial_distribution; + using rep = Q::rep; + using base = std::binomial_distribution; binomial_distribution() : base() {} binomial_distribution(const Q& t, double p) : base(t.numerical_value_ref_in(Q::unit), p) {} @@ -164,8 +164,8 @@ struct binomial_distribution : public std::binomial_distribution requires std::integral struct negative_binomial_distribution : public std::negative_binomial_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::negative_binomial_distribution; + using rep = Q::rep; + using base = std::negative_binomial_distribution; negative_binomial_distribution() : base() {} negative_binomial_distribution(const Q& k, double p) : base(k.numerical_value_ref_in(Q::unit), p) {} @@ -185,8 +185,8 @@ struct negative_binomial_distribution : public std::negative_binomial_distributi template requires std::integral struct geometric_distribution : public std::geometric_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::geometric_distribution; + using rep = Q::rep; + using base = std::geometric_distribution; geometric_distribution() : base() {} explicit geometric_distribution(double p) : base(p) {} @@ -204,8 +204,8 @@ struct geometric_distribution : public std::geometric_distribution requires std::integral struct poisson_distribution : public std::poisson_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::poisson_distribution; + using rep = Q::rep; + using base = std::poisson_distribution; poisson_distribution() : base() {} explicit poisson_distribution(double p) : base(p) {} @@ -223,8 +223,8 @@ struct poisson_distribution : public std::poisson_distribution template requires std::floating_point struct exponential_distribution : public std::exponential_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::exponential_distribution; + using rep = Q::rep; + using base = std::exponential_distribution; exponential_distribution() : base() {} explicit exponential_distribution(const rep& lambda) : base(lambda) {} @@ -242,8 +242,8 @@ struct exponential_distribution : public std::exponential_distribution requires std::floating_point struct gamma_distribution : public std::gamma_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::gamma_distribution; + using rep = Q::rep; + using base = std::gamma_distribution; gamma_distribution() : base() {} gamma_distribution(const rep& alpha, const rep& beta) : base(alpha, beta) {} @@ -261,8 +261,8 @@ struct gamma_distribution : public std::gamma_distribution { template requires std::floating_point struct weibull_distribution : public std::weibull_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::weibull_distribution; + using rep = Q::rep; + using base = std::weibull_distribution; weibull_distribution() : base() {} weibull_distribution(const rep& a, const rep& b) : base(a, b) {} @@ -280,8 +280,8 @@ struct weibull_distribution : public std::weibull_distribution template requires std::floating_point struct extreme_value_distribution : public std::extreme_value_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::extreme_value_distribution; + using rep = Q::rep; + using base = std::extreme_value_distribution; extreme_value_distribution() : base() {} extreme_value_distribution(const Q& a, const rep& b) : base(a.numerical_value_ref_in(Q::unit), b) {} @@ -301,8 +301,8 @@ struct extreme_value_distribution : public std::extreme_value_distribution requires std::floating_point struct normal_distribution : public std::normal_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::normal_distribution; + using rep = Q::rep; + using base = std::normal_distribution; normal_distribution() : base() {} normal_distribution(const Q& mean, const Q& stddev) : @@ -326,8 +326,8 @@ struct normal_distribution : public std::normal_distribution { template requires std::floating_point struct lognormal_distribution : public std::lognormal_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::lognormal_distribution; + using rep = Q::rep; + using base = std::lognormal_distribution; lognormal_distribution() : base() {} lognormal_distribution(const Q& m, const Q& s) : @@ -351,8 +351,8 @@ struct lognormal_distribution : public std::lognormal_distribution requires std::floating_point struct chi_squared_distribution : public std::chi_squared_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::chi_squared_distribution; + using rep = Q::rep; + using base = std::chi_squared_distribution; chi_squared_distribution() : base() {} explicit chi_squared_distribution(const rep& n) : base(n) {} @@ -370,8 +370,8 @@ struct chi_squared_distribution : public std::chi_squared_distribution requires std::floating_point struct cauchy_distribution : public std::cauchy_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::cauchy_distribution; + using rep = Q::rep; + using base = std::cauchy_distribution; cauchy_distribution() : base() {} cauchy_distribution(const Q& a, const Q& b) : @@ -395,8 +395,8 @@ struct cauchy_distribution : public std::cauchy_distribution { template requires std::floating_point struct fisher_f_distribution : public std::fisher_f_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::fisher_f_distribution; + using rep = Q::rep; + using base = std::fisher_f_distribution; fisher_f_distribution() : base() {} fisher_f_distribution(const rep& m, const rep& n) : base(m, n) {} @@ -414,8 +414,8 @@ struct fisher_f_distribution : public std::fisher_f_distribution requires std::floating_point struct student_t_distribution : public std::student_t_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::student_t_distribution; + using rep = Q::rep; + using base = std::student_t_distribution; student_t_distribution() : base() {} explicit student_t_distribution(const rep& n) : base(n) {} @@ -433,8 +433,8 @@ struct student_t_distribution : public std::student_t_distribution requires std::integral struct discrete_distribution : public std::discrete_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::discrete_distribution; + using rep = Q::rep; + using base = std::discrete_distribution; discrete_distribution() : base() {} @@ -464,8 +464,8 @@ struct discrete_distribution : public std::discrete_distribution requires std::floating_point class piecewise_constant_distribution : public std::piecewise_constant_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::piecewise_constant_distribution; + using rep = Q::rep; + using base = std::piecewise_constant_distribution; template piecewise_constant_distribution(const std::vector& i, InputIt first_w) : base(i.cbegin(), i.cend(), first_w) @@ -523,8 +523,8 @@ public: template requires std::floating_point class piecewise_linear_distribution : public std::piecewise_linear_distribution { - using rep = MP_UNITS_TYPENAME Q::rep; - using base = MP_UNITS_TYPENAME std::piecewise_linear_distribution; + using rep = Q::rep; + using base = std::piecewise_linear_distribution; template piecewise_linear_distribution(const std::vector& i, InputIt first_w) : base(i.cbegin(), i.cend(), first_w) diff --git a/src/systems/include/mp-units/systems/si/chrono.h b/src/systems/include/mp-units/systems/si/chrono.h index c018e8d1..5dfbb7fc 100644 --- a/src/systems/include/mp-units/systems/si/chrono.h +++ b/src/systems/include/mp-units/systems/si/chrono.h @@ -137,8 +137,8 @@ template QP> requires is_specialization_of, chrono_point_origin_> [[nodiscard]] constexpr auto to_chrono_time_point(const QP& qp) { - using clock = MP_UNITS_TYPENAME decltype(QP::absolute_point_origin)::clock; - using rep = MP_UNITS_TYPENAME QP::rep; + using clock = decltype(QP::absolute_point_origin)::clock; + using rep = QP::rep; using ret_type = std::chrono::time_point>; From 712afc34b7f03b1e79d79dc9884c22dacdc775eb Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:37:41 +0200 Subject: [PATCH 30/44] [PR] rename macros to match naming conventions for workaround --- .../mp-units/bits/get_associated_quantity.h | 4 +- src/core/include/mp-units/bits/hacks.h | 24 +++---- .../mp-units/framework/construction_helpers.h | 4 +- .../mp-units/framework/quantity_point.h | 4 +- .../mp-units/framework/quantity_spec.h | 64 +++++++++---------- .../include/mp-units/framework/reference.h | 24 +++---- src/core/include/mp-units/framework/unit.h | 2 +- .../include/mp-units/systems/si/chrono.h | 4 +- .../include/mp-units/systems/si/math.h | 14 ++-- 9 files changed, 68 insertions(+), 76 deletions(-) diff --git a/src/core/include/mp-units/bits/get_associated_quantity.h b/src/core/include/mp-units/bits/get_associated_quantity.h index 1339ca0f..d3783b18 100644 --- a/src/core/include/mp-units/bits/get_associated_quantity.h +++ b/src/core/include/mp-units/bits/get_associated_quantity.h @@ -76,9 +76,9 @@ template template [[nodiscard]] consteval auto get_associated_quantity(U u) { - constexpr bool all_kinds = all_are_kinds(MP_UNITS_IS_CONST_EXPR(u)); + constexpr bool all_kinds = all_are_kinds(MP_UNITS_IS_CONST_EXPR_WORKAROUND(u)); if constexpr (all_kinds) - return kind_of; + return kind_of; else return get_associated_quantity_impl(u); } diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 253738e3..80b597ac 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -77,21 +77,6 @@ #define MP_UNITS_HOSTED __STDC_HOSTED__ #endif -#if MP_UNITS_COMP_MSVC - -#define MP_UNITS_EXPRESSION(x) (x) -#define MP_UNITS_IS_VALUE(x) (x) -#define MP_UNITS_IS_CONST_EXPR(x) \ - decltype(x) {} - -#else - -#define MP_UNITS_EXPRESSION(x) x -#define MP_UNITS_IS_VALUE(x) x -#define MP_UNITS_IS_CONST_EXPR(x) x - -#endif - #if MP_UNITS_COMP_GCC #define MP_UNITS_REMOVE_CONST(expr) std::remove_const_t @@ -129,11 +114,18 @@ inline constexpr from_range_t from_range{}; #define MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(X) #define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) +#define MP_UNITS_EXPRESSION_WORKAROUND(x) (x) +#define MP_UNITS_IS_VALUE_WORKAROUND(x) (x) +#define MP_UNITS_IS_CONST_EXPR_WORKAROUND(x) \ + decltype(x) {} #else #define MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(X) X -#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X +#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X' +#define MP_UNITS_EXPRESSION_WORKAROUND(x) x +#define MP_UNITS_IS_VALUE_WORKAROUND(x) x +#define MP_UNITS_IS_CONST_EXPR_WORKAROUND(x) x #endif diff --git a/src/core/include/mp-units/framework/construction_helpers.h b/src/core/include/mp-units/framework/construction_helpers.h index 9b5f9be9..5a719a0d 100644 --- a/src/core/include/mp-units/framework/construction_helpers.h +++ b/src/core/include/mp-units/framework/construction_helpers.h @@ -41,7 +41,7 @@ template struct delta_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity> operator()(Rep&& lhs) const + [[nodiscard]] constexpr quantity< MP_UNITS_EXPRESSION_WORKAROUND(R{}), std::remove_cvref_t> operator()(Rep&& lhs) const { return quantity{std::forward(lhs), R{}}; } @@ -51,7 +51,7 @@ template struct absolute_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity_point> + [[nodiscard]] constexpr quantity_point< MP_UNITS_EXPRESSION_WORKAROUND(R{}), default_point_origin(R{}), std::remove_cvref_t> operator()(Rep&& lhs) const { return quantity_point{quantity{std::forward(lhs), R{}}}; diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index c7d60319..99cc59f9 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -54,7 +54,7 @@ template struct point_origin_interface { template requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+( + [[nodiscard]] friend constexpr quantity_point operator+( PO, Q&& q) { return quantity_point{std::forward(q), PO{}}; @@ -62,7 +62,7 @@ struct point_origin_interface { template requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+( + [[nodiscard]] friend constexpr quantity_point operator+( Q&& q, PO po) { return po + std::forward(q); diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 664f26fc..b285d7e0 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -673,10 +673,10 @@ template template [[nodiscard]] consteval bool ingredients_dimension_less(D1 lhs, D2 rhs) { - if constexpr (MP_UNITS_IS_CONST_EXPR(lhs) == MP_UNITS_IS_CONST_EXPR(rhs) || - MP_UNITS_IS_CONST_EXPR(lhs) == dimension_one) + if constexpr (MP_UNITS_IS_CONST_EXPR_WORKAROUND(lhs) == MP_UNITS_IS_CONST_EXPR_WORKAROUND(rhs) || + MP_UNITS_IS_CONST_EXPR_WORKAROUND(lhs) == dimension_one) return false; - else if constexpr (MP_UNITS_IS_CONST_EXPR(rhs) == dimension_one) + else if constexpr (MP_UNITS_IS_CONST_EXPR_WORKAROUND(rhs) == dimension_one) return true; else return detail::type_name() < detail::type_name(); @@ -1345,21 +1345,21 @@ template using enum specs_convertible_result; return res == no ? no : yes; }; - if constexpr ((NamedQuantitySpec && - NamedQuantitySpec) || - get_complexity(MP_UNITS_IS_CONST_EXPR(from_kind)) == get_complexity(MP_UNITS_IS_CONST_EXPR(to_kind))) - return convertible_impl(MP_UNITS_IS_CONST_EXPR(from_kind), MP_UNITS_IS_CONST_EXPR(to_kind)); - else if constexpr (get_complexity(MP_UNITS_IS_CONST_EXPR(from_kind)) > - get_complexity(MP_UNITS_IS_CONST_EXPR(to_kind))) + if constexpr ((NamedQuantitySpec && + NamedQuantitySpec) || + get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) == get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))) + return convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)); + else if constexpr (get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) > + get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))) return exploded_kind_result(convertible_impl( get_kind_tree_root( - explode(MP_UNITS_IS_CONST_EXPR(from_kind)).quantity), - MP_UNITS_IS_CONST_EXPR(to_kind))); + explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)).quantity), + MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))); else return exploded_kind_result(convertible_impl( - MP_UNITS_IS_CONST_EXPR(from_kind), + MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), get_kind_tree_root( - explode(MP_UNITS_IS_CONST_EXPR(to_kind)).quantity))); + explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)).quantity))); } template @@ -1377,11 +1377,11 @@ template else if constexpr (get_complexity(From{}) != get_complexity(To{})) { if constexpr (get_complexity(From{}) > get_complexity(To{})) return convertible_impl( - explode(MP_UNITS_IS_CONST_EXPR(from)).quantity, - MP_UNITS_IS_CONST_EXPR(to)); + explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)).quantity, + MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); else { - auto res = explode(MP_UNITS_IS_CONST_EXPR(to)); - return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR(from), res.quantity)); + auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), res.quantity)); } } } @@ -1397,31 +1397,31 @@ template else if constexpr (From::dimension != To::dimension) return no; else if constexpr (QuantityKindSpec || QuantityKindSpec) - return convertible_kinds(get_kind_tree_root(MP_UNITS_IS_CONST_EXPR(from)), - get_kind_tree_root(MP_UNITS_IS_CONST_EXPR(to))); + return convertible_kinds(get_kind_tree_root(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)), + get_kind_tree_root(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to))); else if constexpr (NestedQuantityKindSpecOf && get_kind_tree_root(To{}) == To{}) return yes; else if constexpr (NamedQuantitySpec && NamedQuantitySpec) - return convertible_named(MP_UNITS_IS_CONST_EXPR(from), MP_UNITS_IS_CONST_EXPR(to)); + return convertible_named(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); else if constexpr (DerivedQuantitySpec && DerivedQuantitySpec) - return are_ingredients_convertible(from, MP_UNITS_IS_CONST_EXPR(to)); + return are_ingredients_convertible(from, MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); else if constexpr (DerivedQuantitySpec) { - auto res = explode(MP_UNITS_IS_CONST_EXPR(from)); + auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)); if constexpr (NamedQuantitySpec) - return convertible_impl(res.quantity, MP_UNITS_IS_CONST_EXPR(to)); - else if constexpr (requires { MP_UNITS_IS_CONST_EXPR(to)._equation_; }) { - auto eq = explode_to_equation(MP_UNITS_IS_CONST_EXPR(to)); + return convertible_impl(res.quantity, MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + else if constexpr (requires { MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)._equation_; }) { + auto eq = explode_to_equation(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); return min(eq.result, convertible_impl(res.quantity, eq.equation)); } else - return are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR(from), MP_UNITS_IS_CONST_EXPR(to)); + return are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); } else if constexpr (DerivedQuantitySpec) { - auto res = explode(MP_UNITS_IS_CONST_EXPR(to)); + auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); if constexpr (NamedQuantitySpec) - return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR(from), res.quantity)); - else if constexpr (requires { MP_UNITS_IS_CONST_EXPR(from)._equation_; }) - return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR(from)._equation_, res.quantity)); + return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), res.quantity)); + else if constexpr (requires { MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)._equation_; }) + return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)._equation_, res.quantity)); else - return min(res.result, are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR(from), MP_UNITS_IS_CONST_EXPR(to))); + return min(res.result, are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to))); } // NOLINTEND(bugprone-branch-clone) return no; @@ -1508,7 +1508,7 @@ MP_UNITS_EXPORT_BEGIN template [[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q q) { - return kind_of; + return kind_of; } [[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q) { return q; } diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index c946476e..7b7ea927 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -87,46 +87,46 @@ struct reference { } template - [[nodiscard]] friend consteval detail::reference_t + [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} * Q2{}), MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> operator*(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t<(MP_UNITS_EXPRESSION(Q{} * get_quantity_spec(U2{}))), - MP_UNITS_EXPRESSION(U{} * U2{})> + [[nodiscard]] friend consteval detail::reference_t<( MP_UNITS_EXPRESSION_WORKAROUND(Q{} * get_quantity_spec(U2{}))), + MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> operator*(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t + [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) * Q{}), + MP_UNITS_EXPRESSION_WORKAROUND(U1{} * U{})> operator*(U1, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t + [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} / Q2{}), MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})> operator/(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t + [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} / get_quantity_spec(U2{})), + MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})> operator/(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t + [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) / Q{}), + MP_UNITS_EXPRESSION_WORKAROUND(U1{} / U{})> operator/(U1, reference) { return {}; @@ -296,9 +296,9 @@ template } { return detail::reference_t< - common_quantity_spec(get_quantity_spec(MP_UNITS_IS_CONST_EXPR(r1)), get_quantity_spec(MP_UNITS_IS_CONST_EXPR(r2)), + common_quantity_spec(get_quantity_spec(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r1)), get_quantity_spec(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r2)), get_quantity_spec(rest)...), - common_unit(get_unit(MP_UNITS_IS_CONST_EXPR(r1)), get_unit(MP_UNITS_IS_CONST_EXPR(r2)), get_unit(rest)...)>{}; + common_unit(get_unit(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r1)), get_unit(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r2)), get_unit(rest)...)>{}; } MP_UNITS_EXPORT_END diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index ba39dbb8..d5e61c5f 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -633,7 +633,7 @@ template template [[nodiscard]] consteval Unit auto common_unit(U1 u1, U2 u2) - requires(convertible(MP_UNITS_IS_CONST_EXPR(u1), MP_UNITS_IS_CONST_EXPR(u2))) + requires(convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(u1), MP_UNITS_IS_CONST_EXPR_WORKAROUND(u2))) { if constexpr (is_same_v) return u1; diff --git a/src/systems/include/mp-units/systems/si/chrono.h b/src/systems/include/mp-units/systems/si/chrono.h index 5dfbb7fc..b4ba90be 100644 --- a/src/systems/include/mp-units/systems/si/chrono.h +++ b/src/systems/include/mp-units/systems/si/chrono.h @@ -127,13 +127,13 @@ namespace detail { } // namespace detail -template Q> +template Q> [[nodiscard]] constexpr auto to_chrono_duration(const Q& q) { return std::chrono::duration{q}; } -template QP> +template QP> requires is_specialization_of, chrono_point_origin_> [[nodiscard]] constexpr auto to_chrono_time_point(const QP& qp) { diff --git a/src/systems/include/mp-units/systems/si/math.h b/src/systems/include/mp-units/systems/si/math.h index a7bc0cec..c91d0df8 100644 --- a/src/systems/include/mp-units/systems/si/math.h +++ b/src/systems/include/mp-units/systems/si/math.h @@ -43,7 +43,7 @@ import std; MP_UNITS_EXPORT namespace mp_units::si { -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { sin(v); } || requires(Rep v) { std::sin(v); } [[nodiscard]] inline QuantityOf auto sin(const quantity& q) noexcept { @@ -57,7 +57,7 @@ template auto R, typename R return quantity{sin(q.numerical_value_in(radian)), one}; } -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { cos(v); } || requires(Rep v) { std::cos(v); } [[nodiscard]] inline QuantityOf auto cos(const quantity& q) noexcept { @@ -71,7 +71,7 @@ template auto R, typename R return quantity{cos(q.numerical_value_in(radian)), one}; } -template auto R, typename Rep> +template auto R, typename Rep> requires requires(Rep v) { tan(v); } || requires(Rep v) { std::tan(v); } [[nodiscard]] inline QuantityOf auto tan(const quantity& q) noexcept { @@ -87,7 +87,7 @@ template auto R, typename R template auto R, typename Rep> requires requires(Rep v) { asin(v); } || requires(Rep v) { std::asin(v); } -[[nodiscard]] inline QuantityOf auto asin(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto asin(const quantity& q) noexcept { using std::asin; if constexpr (!treat_as_floating_point) { @@ -101,7 +101,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { acos(v); } || requires(Rep v) { std::acos(v); } -[[nodiscard]] inline QuantityOf auto acos(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto acos(const quantity& q) noexcept { using std::acos; if constexpr (!treat_as_floating_point) { @@ -115,7 +115,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { atan(v); } || requires(Rep v) { std::atan(v); } -[[nodiscard]] inline QuantityOf auto atan(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto atan(const quantity& q) noexcept { using std::atan; if constexpr (!treat_as_floating_point) { @@ -132,7 +132,7 @@ template common_reference(R1, R2); requires requires { atan2(v1, v2); } || requires { std::atan2(v1, v2); }; } -[[nodiscard]] inline QuantityOf auto atan2( +[[nodiscard]] inline QuantityOf auto atan2( const quantity& y, const quantity& x) noexcept { constexpr auto ref = common_reference(R1, R2); From b05b3796ce3d927301ae6d699061132c987d82d9 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Wed, 4 Sep 2024 09:49:04 +0200 Subject: [PATCH 31/44] [PR] move is_mp_units_stream to detail and change from concept to constexpr function --- src/core/include/mp-units/ostream.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/include/mp-units/ostream.h b/src/core/include/mp-units/ostream.h index 0b073225..15b6127b 100644 --- a/src/core/include/mp-units/ostream.h +++ b/src/core/include/mp-units/ostream.h @@ -85,16 +85,16 @@ std::basic_ostream& to_stream(std::basic_ostream& return os; } +template +constexpr bool is_mp_units_stream = requires(OStream os, T v) { detail::to_stream_impl(os, v); }; + } // namespace detail MP_UNITS_EXPORT_BEGIN -template -concept is_mp_units_stream = requires(OStream os, T v) { detail::to_stream_impl(os, v); }; - template std::basic_ostream& operator<<(std::basic_ostream& os, const T& v) - requires is_mp_units_stream, T> + requires detail::is_mp_units_stream, T> { return detail::to_stream(os, v); } From 8be458b0b753f83091e655037d9f69a2889d339e Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:19:15 +0200 Subject: [PATCH 32/44] [msvc] remove MP_UNITS_CONSTRAINED_AUTO_WORKAROUND --- example/measurement.cpp | 2 +- src/core/include/mp-units/bits/hacks.h | 5 +---- src/core/include/mp-units/framework/unit.h | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/example/measurement.cpp b/example/measurement.cpp index 5e1e5419..2aca3077 100644 --- a/example/measurement.cpp +++ b/example/measurement.cpp @@ -151,7 +151,7 @@ void example() const auto acceleration = isq::acceleration(measurement{9.8, 0.1} * m / s2); const auto time = measurement{1.2, 0.1} * s; - const MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(QuantityOf) auto velocity = acceleration * time; + const QuantityOf<(isq::velocity)> auto velocity = acceleration * time; std::cout << acceleration << " * " << time << " = " << velocity << " = " << velocity.in(km / h) << '\n'; const auto length = measurement{123., 1.} * m; diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 80b597ac..6b95c371 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -76,7 +76,6 @@ #if !defined MP_UNITS_HOSTED && defined __STDC_HOSTED__ #define MP_UNITS_HOSTED __STDC_HOSTED__ #endif - #if MP_UNITS_COMP_GCC #define MP_UNITS_REMOVE_CONST(expr) std::remove_const_t @@ -112,7 +111,6 @@ inline constexpr from_range_t from_range{}; #if MP_UNITS_COMP_MSVC -#define MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(X) #define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) #define MP_UNITS_EXPRESSION_WORKAROUND(x) (x) #define MP_UNITS_IS_VALUE_WORKAROUND(x) (x) @@ -121,8 +119,7 @@ inline constexpr from_range_t from_range{}; #else -#define MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(X) X -#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X' +#define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X #define MP_UNITS_EXPRESSION_WORKAROUND(x) x #define MP_UNITS_IS_VALUE_WORKAROUND(x) x #define MP_UNITS_IS_CONST_EXPR_WORKAROUND(x) x diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index d5e61c5f..f49dcd9b 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -220,7 +220,7 @@ struct propagate_point_origin { template struct scaled_unit_impl : detail::unit_interface, detail::propagate_point_origin { using _base_type_ = scaled_unit_impl; // exposition only - static constexpr MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(Magnitude) auto mag = M; + static constexpr Magnitude auto mag = M; static constexpr U reference_unit{}; }; From 93af5db13723ccc8978e0577e1774923a35477d5 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:30:39 +0200 Subject: [PATCH 33/44] [clang-format] --- example/measurement.cpp | 2 +- src/core/include/mp-units/bits/hacks.h | 2 +- src/core/include/mp-units/bits/sudo_cast.h | 13 ++-- src/core/include/mp-units/bits/type_list.h | 26 +++---- src/core/include/mp-units/ext/type_traits.h | 12 +-- .../mp-units/framework/construction_helpers.h | 6 +- .../mp-units/framework/expression_template.h | 11 ++- .../mp-units/framework/quantity_point.h | 8 +- .../mp-units/framework/quantity_spec.h | 33 ++++---- .../include/mp-units/framework/reference.h | 31 ++++---- src/core/include/mp-units/random.h | 78 +++++++++---------- .../include/mp-units/systems/si/chrono.h | 4 +- .../include/mp-units/systems/si/math.h | 9 ++- 13 files changed, 124 insertions(+), 111 deletions(-) diff --git a/example/measurement.cpp b/example/measurement.cpp index 2aca3077..b545d614 100644 --- a/example/measurement.cpp +++ b/example/measurement.cpp @@ -151,7 +151,7 @@ void example() const auto acceleration = isq::acceleration(measurement{9.8, 0.1} * m / s2); const auto time = measurement{1.2, 0.1} * s; - const QuantityOf<(isq::velocity)> auto velocity = acceleration * time; + const QuantityOf auto velocity = acceleration * time; std::cout << acceleration << " * " << time << " = " << velocity << " = " << velocity.in(km / h) << '\n'; const auto length = measurement{123., 1.} * m; diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 6b95c371..4b732c5d 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -120,7 +120,7 @@ inline constexpr from_range_t from_range{}; #else #define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X -#define MP_UNITS_EXPRESSION_WORKAROUND(x) x +#define MP_UNITS_EXPRESSION_WORKAROUND(x) x #define MP_UNITS_IS_VALUE_WORKAROUND(x) x #define MP_UNITS_IS_CONST_EXPR_WORKAROUND(x) x diff --git a/src/core/include/mp-units/bits/sudo_cast.h b/src/core/include/mp-units/bits/sudo_cast.h index b96c3e34..69379128 100644 --- a/src/core/include/mp-units/bits/sudo_cast.h +++ b/src/core/include/mp-units/bits/sudo_cast.h @@ -46,7 +46,7 @@ template struct get_common_type : std::common_type {}; template -using maybe_common_type = +using maybe_common_type = std::conditional_t, get_common_type, std::type_identity>::type; /** @@ -108,7 +108,7 @@ template constexpr auto q_unit = std::remove_reference_t::unit; if constexpr (q_unit == To::unit) { // no scaling of the number needed - return {static_cast< To::rep>(std::forward(q).numerical_value_is_an_implementation_detail_), + return {static_cast(std::forward(q).numerical_value_is_an_implementation_detail_), To::reference}; // this is the only (and recommended) way to do a truncating conversion on a number, so we // are using static_cast to suppress all the compiler warnings on conversions } else { @@ -116,14 +116,13 @@ template using traits = magnitude_conversion_traits>; if constexpr (std::is_floating_point_v) { // this results in great assembly - auto res = static_cast< To::rep>( - static_cast(q.numerical_value_is_an_implementation_detail_) * traits::ratio); + auto res = static_cast(static_cast(q.numerical_value_is_an_implementation_detail_) * + traits::ratio); return {res, To::reference}; } else { // this is slower but allows conversions like 2000 m -> 2 km without loosing data - auto res = static_cast< To::rep>( - static_cast(q.numerical_value_is_an_implementation_detail_) * traits::num_mult / - traits::den_mult * traits::irr_mult); + auto res = static_cast(static_cast(q.numerical_value_is_an_implementation_detail_) * + traits::num_mult / traits::den_mult * traits::irr_mult); return {res, To::reference}; } } diff --git a/src/core/include/mp-units/bits/type_list.h b/src/core/include/mp-units/bits/type_list.h index be9ea15c..c40d0045 100644 --- a/src/core/include/mp-units/bits/type_list.h +++ b/src/core/include/mp-units/bits/type_list.h @@ -68,7 +68,7 @@ struct type_list_map_impl, To> { }; template typename To> -using type_list_map = type_list_map_impl::type; +using type_list_map = type_list_map_impl::type; // element @@ -105,7 +105,7 @@ struct type_list_front_impl> { }; template -using type_list_front = type_list_front_impl::type; +using type_list_front = type_list_front_impl::type; // back template @@ -121,7 +121,7 @@ struct type_list_push_front_impl, NewTypes...> { }; template -using type_list_push_front = type_list_push_front_impl::type; +using type_list_push_front = type_list_push_front_impl::type; // push_back template @@ -133,7 +133,7 @@ struct type_list_push_back_impl, NewTypes...> { }; template -using type_list_push_back = type_list_push_back_impl::type; +using type_list_push_back = type_list_push_back_impl::type; // join template @@ -143,11 +143,11 @@ struct type_list_join_impl { template typename List, typename... First, typename... Second, typename... Rest> struct type_list_join_impl, List, Rest...> { - using type = type_list_join_impl, Rest...>::type; + using type = type_list_join_impl, Rest...>::type; }; template -using type_list_join = type_list_join_impl::type; +using type_list_join = type_list_join_impl::type; // split template @@ -195,19 +195,19 @@ template typename List, typename Lhs1, typename... LhsRest template typename Pred> requires Pred::value struct type_list_merge_sorted_impl, List, Pred> { - using type = type_list_push_front_impl< + using type = type_list_push_front_impl< typename type_list_merge_sorted_impl, List, Pred>::type, Lhs1>::type; }; template typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest, template typename Pred> struct type_list_merge_sorted_impl, List, Pred> { - using type = type_list_push_front_impl< + using type = type_list_push_front_impl< typename type_list_merge_sorted_impl, List, Pred>::type, Rhs1>::type; }; template typename Pred> -using type_list_merge_sorted = type_list_merge_sorted_impl::type; +using type_list_merge_sorted = type_list_merge_sorted_impl::type; // sort template typename Pred> @@ -227,13 +227,13 @@ template typename List, typename... Types, template, Pred> { using types = List; using split = type_list_split_half>; - using sorted_left = type_list_sort_impl::type; - using sorted_right = type_list_sort_impl::type; - using type = type_list_merge_sorted_impl::type; + using sorted_left = type_list_sort_impl::type; + using sorted_right = type_list_sort_impl::type; + using type = type_list_merge_sorted_impl::type; }; template typename Pred> -using type_list_sort = type_list_sort_impl::type; +using type_list_sort = type_list_sort_impl::type; } // namespace mp_units::detail diff --git a/src/core/include/mp-units/ext/type_traits.h b/src/core/include/mp-units/ext/type_traits.h index 1ffd715e..d6b728c5 100644 --- a/src/core/include/mp-units/ext/type_traits.h +++ b/src/core/include/mp-units/ext/type_traits.h @@ -56,7 +56,7 @@ struct conditional_impl { MP_UNITS_EXPORT_BEGIN template -using conditional = detail::conditional_impl::template type; +using conditional = detail::conditional_impl::template type; // is_same template @@ -99,7 +99,7 @@ namespace detail { template struct get_value_type { - using type = T::value_type; + using type = T::value_type; }; template @@ -112,13 +112,13 @@ struct get_element_type { template requires requires { typename T::value_type; } || requires { typename T::element_type; } struct wrapped_type { - using type = + using type = conditional, detail::get_element_type>::type; }; template requires requires { typename T::value_type; } || requires { typename T::element_type; } -using wrapped_type_t = wrapped_type::type; +using wrapped_type_t = wrapped_type::type; template struct value_type { @@ -128,11 +128,11 @@ struct value_type { template requires requires { typename wrapped_type_t; } struct value_type { - using type = wrapped_type_t; + using type = wrapped_type_t; }; template -using value_type_t = value_type::type; +using value_type_t = value_type::type; template concept one_of = (false || ... || std::same_as); diff --git a/src/core/include/mp-units/framework/construction_helpers.h b/src/core/include/mp-units/framework/construction_helpers.h index 5a719a0d..9830dccb 100644 --- a/src/core/include/mp-units/framework/construction_helpers.h +++ b/src/core/include/mp-units/framework/construction_helpers.h @@ -41,7 +41,8 @@ template struct delta_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity< MP_UNITS_EXPRESSION_WORKAROUND(R{}), std::remove_cvref_t> operator()(Rep&& lhs) const + [[nodiscard]] constexpr quantity> operator()( + Rep&& lhs) const { return quantity{std::forward(lhs), R{}}; } @@ -51,7 +52,8 @@ template struct absolute_ { template requires RepresentationOf, get_quantity_spec(R{}).character> - [[nodiscard]] constexpr quantity_point< MP_UNITS_EXPRESSION_WORKAROUND(R{}), default_point_origin(R{}), std::remove_cvref_t> + [[nodiscard]] constexpr quantity_point> operator()(Rep&& lhs) const { return quantity_point{quantity{std::forward(lhs), R{}}}; diff --git a/src/core/include/mp-units/framework/expression_template.h b/src/core/include/mp-units/framework/expression_template.h index 2b607130..0ae1251c 100644 --- a/src/core/include/mp-units/framework/expression_template.h +++ b/src/core/include/mp-units/framework/expression_template.h @@ -122,7 +122,7 @@ struct expr_type_impl> : std::type_identity {}; } // namespace detail template -using expr_type = detail::expr_type_impl::type; +using expr_type = detail::expr_type_impl::type; namespace detail { @@ -182,25 +182,24 @@ struct expr_consolidate_impl> { template requires(!is_specialization_of_power) struct expr_consolidate_impl> { - using type = expr_consolidate_impl, Rest...>>::type; + using type = expr_consolidate_impl, Rest...>>::type; }; // replaces the instance of a type and a power of it with one with incremented power template struct expr_consolidate_impl, Rest...>> { - using type = - expr_consolidate_impl::exponent + 1>, Rest...>>::type; + using type = expr_consolidate_impl::exponent + 1>, Rest...>>::type; }; // accumulates the powers of instances of the same type (removes the element in case the accumulation result is `0`) template struct expr_consolidate_impl, power, Rest...>> { static constexpr ratio r = power::exponent + power::exponent; - using type = expr_consolidate_impl, Rest...>>::type; + using type = expr_consolidate_impl, Rest...>>::type; }; template -using expr_consolidate = expr_consolidate_impl::type; +using expr_consolidate = expr_consolidate_impl::type; /** diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index 99cc59f9..fc6a2efd 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -54,16 +54,16 @@ template struct point_origin_interface { template requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+( - PO, Q&& q) + [[nodiscard]] friend constexpr quantity_point + operator+(PO, Q&& q) { return quantity_point{std::forward(q), PO{}}; } template requires ReferenceOf, PO::quantity_spec> - [[nodiscard]] friend constexpr quantity_point operator+( - Q&& q, PO po) + [[nodiscard]] friend constexpr quantity_point + operator+(Q&& q, PO po) { return po + std::forward(q); } diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index b285d7e0..fbb54a4e 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -1347,19 +1347,22 @@ template }; if constexpr ((NamedQuantitySpec && NamedQuantitySpec) || - get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) == get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))) + get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) == + get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))) return convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)); else if constexpr (get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) > get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))) - return exploded_kind_result(convertible_impl( - get_kind_tree_root( - explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)).quantity), - MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))); + return exploded_kind_result( + convertible_impl(get_kind_tree_root(explode( + MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) + .quantity), + MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))); else - return exploded_kind_result(convertible_impl( - MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), - get_kind_tree_root( - explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)).quantity))); + return exploded_kind_result( + convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), + get_kind_tree_root(explode( + MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)) + .quantity))); } template @@ -1377,10 +1380,12 @@ template else if constexpr (get_complexity(From{}) != get_complexity(To{})) { if constexpr (get_complexity(From{}) > get_complexity(To{})) return convertible_impl( - explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)).quantity, + explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)) + .quantity, MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); else { - auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + auto res = + explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), res.quantity)); } } @@ -1413,7 +1418,8 @@ template auto eq = explode_to_equation(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); return min(eq.result, convertible_impl(res.quantity, eq.equation)); } else - return are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + return are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), + MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); } else if constexpr (DerivedQuantitySpec) { auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); if constexpr (NamedQuantitySpec) @@ -1421,7 +1427,8 @@ template else if constexpr (requires { MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)._equation_; }) return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)._equation_, res.quantity)); else - return min(res.result, are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to))); + return min(res.result, are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), + MP_UNITS_IS_CONST_EXPR_WORKAROUND(to))); } // NOLINTEND(bugprone-branch-clone) return no; diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index 7b7ea927..4af6ab5b 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -87,46 +87,48 @@ struct reference { } template - [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} * Q2{}), MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> + [[nodiscard]] friend consteval detail::reference_t operator*(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t<( MP_UNITS_EXPRESSION_WORKAROUND(Q{} * get_quantity_spec(U2{}))), - MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> + [[nodiscard]] friend consteval detail::reference_t<(MP_UNITS_EXPRESSION_WORKAROUND(Q{} * get_quantity_spec(U2{}))), + MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> operator*(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) * Q{}), - MP_UNITS_EXPRESSION_WORKAROUND(U1{} * U{})> + [[nodiscard]] friend consteval detail::reference_t operator*(U1, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} / Q2{}), MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})> + [[nodiscard]] friend consteval detail::reference_t operator/(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} / get_quantity_spec(U2{})), - MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})> + [[nodiscard]] friend consteval detail::reference_t operator/(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) / Q{}), - MP_UNITS_EXPRESSION_WORKAROUND(U1{} / U{})> + [[nodiscard]] friend consteval detail::reference_t operator/(U1, reference) { return {}; @@ -295,10 +297,11 @@ template } -> Unit; } { - return detail::reference_t< - common_quantity_spec(get_quantity_spec(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r1)), get_quantity_spec(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r2)), - get_quantity_spec(rest)...), - common_unit(get_unit(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r1)), get_unit(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r2)), get_unit(rest)...)>{}; + return detail::reference_t{}; } MP_UNITS_EXPORT_END diff --git a/src/core/include/mp-units/random.h b/src/core/include/mp-units/random.h index 05251f3f..5da89966 100644 --- a/src/core/include/mp-units/random.h +++ b/src/core/include/mp-units/random.h @@ -61,7 +61,7 @@ std::vector bl_qty_to_rep(std::initializer_list& bl) template std::vector fw_bl_pwc(std::initializer_list& bl, UnaryOperation fw) { - using rep = Q::rep; + using rep = Q::rep; std::vector w_bl; w_bl.reserve(bl.size()); for (const Q& qty : bl) { @@ -93,8 +93,8 @@ MP_UNITS_EXPORT_BEGIN template requires std::integral struct uniform_int_distribution : public std::uniform_int_distribution { - using rep = Q::rep; - using base = std::uniform_int_distribution; + using rep = Q::rep; + using base = std::uniform_int_distribution; uniform_int_distribution() : base() {} uniform_int_distribution(const Q& a, const Q& b) : @@ -118,8 +118,8 @@ struct uniform_int_distribution : public std::uniform_int_distribution requires std::floating_point struct uniform_real_distribution : public std::uniform_real_distribution { - using rep = Q::rep; - using base = std::uniform_real_distribution; + using rep = Q::rep; + using base = std::uniform_real_distribution; uniform_real_distribution() : base() {} uniform_real_distribution(const Q& a, const Q& b) : @@ -143,8 +143,8 @@ struct uniform_real_distribution : public std::uniform_real_distribution requires std::integral struct binomial_distribution : public std::binomial_distribution { - using rep = Q::rep; - using base = std::binomial_distribution; + using rep = Q::rep; + using base = std::binomial_distribution; binomial_distribution() : base() {} binomial_distribution(const Q& t, double p) : base(t.numerical_value_ref_in(Q::unit), p) {} @@ -164,8 +164,8 @@ struct binomial_distribution : public std::binomial_distribution requires std::integral struct negative_binomial_distribution : public std::negative_binomial_distribution { - using rep = Q::rep; - using base = std::negative_binomial_distribution; + using rep = Q::rep; + using base = std::negative_binomial_distribution; negative_binomial_distribution() : base() {} negative_binomial_distribution(const Q& k, double p) : base(k.numerical_value_ref_in(Q::unit), p) {} @@ -185,8 +185,8 @@ struct negative_binomial_distribution : public std::negative_binomial_distributi template requires std::integral struct geometric_distribution : public std::geometric_distribution { - using rep = Q::rep; - using base = std::geometric_distribution; + using rep = Q::rep; + using base = std::geometric_distribution; geometric_distribution() : base() {} explicit geometric_distribution(double p) : base(p) {} @@ -204,8 +204,8 @@ struct geometric_distribution : public std::geometric_distribution requires std::integral struct poisson_distribution : public std::poisson_distribution { - using rep = Q::rep; - using base = std::poisson_distribution; + using rep = Q::rep; + using base = std::poisson_distribution; poisson_distribution() : base() {} explicit poisson_distribution(double p) : base(p) {} @@ -223,8 +223,8 @@ struct poisson_distribution : public std::poisson_distribution template requires std::floating_point struct exponential_distribution : public std::exponential_distribution { - using rep = Q::rep; - using base = std::exponential_distribution; + using rep = Q::rep; + using base = std::exponential_distribution; exponential_distribution() : base() {} explicit exponential_distribution(const rep& lambda) : base(lambda) {} @@ -242,8 +242,8 @@ struct exponential_distribution : public std::exponential_distribution requires std::floating_point struct gamma_distribution : public std::gamma_distribution { - using rep = Q::rep; - using base = std::gamma_distribution; + using rep = Q::rep; + using base = std::gamma_distribution; gamma_distribution() : base() {} gamma_distribution(const rep& alpha, const rep& beta) : base(alpha, beta) {} @@ -261,8 +261,8 @@ struct gamma_distribution : public std::gamma_distribution { template requires std::floating_point struct weibull_distribution : public std::weibull_distribution { - using rep = Q::rep; - using base = std::weibull_distribution; + using rep = Q::rep; + using base = std::weibull_distribution; weibull_distribution() : base() {} weibull_distribution(const rep& a, const rep& b) : base(a, b) {} @@ -280,8 +280,8 @@ struct weibull_distribution : public std::weibull_distribution template requires std::floating_point struct extreme_value_distribution : public std::extreme_value_distribution { - using rep = Q::rep; - using base = std::extreme_value_distribution; + using rep = Q::rep; + using base = std::extreme_value_distribution; extreme_value_distribution() : base() {} extreme_value_distribution(const Q& a, const rep& b) : base(a.numerical_value_ref_in(Q::unit), b) {} @@ -301,8 +301,8 @@ struct extreme_value_distribution : public std::extreme_value_distribution requires std::floating_point struct normal_distribution : public std::normal_distribution { - using rep = Q::rep; - using base = std::normal_distribution; + using rep = Q::rep; + using base = std::normal_distribution; normal_distribution() : base() {} normal_distribution(const Q& mean, const Q& stddev) : @@ -326,8 +326,8 @@ struct normal_distribution : public std::normal_distribution { template requires std::floating_point struct lognormal_distribution : public std::lognormal_distribution { - using rep = Q::rep; - using base = std::lognormal_distribution; + using rep = Q::rep; + using base = std::lognormal_distribution; lognormal_distribution() : base() {} lognormal_distribution(const Q& m, const Q& s) : @@ -351,8 +351,8 @@ struct lognormal_distribution : public std::lognormal_distribution requires std::floating_point struct chi_squared_distribution : public std::chi_squared_distribution { - using rep = Q::rep; - using base = std::chi_squared_distribution; + using rep = Q::rep; + using base = std::chi_squared_distribution; chi_squared_distribution() : base() {} explicit chi_squared_distribution(const rep& n) : base(n) {} @@ -370,8 +370,8 @@ struct chi_squared_distribution : public std::chi_squared_distribution requires std::floating_point struct cauchy_distribution : public std::cauchy_distribution { - using rep = Q::rep; - using base = std::cauchy_distribution; + using rep = Q::rep; + using base = std::cauchy_distribution; cauchy_distribution() : base() {} cauchy_distribution(const Q& a, const Q& b) : @@ -395,8 +395,8 @@ struct cauchy_distribution : public std::cauchy_distribution { template requires std::floating_point struct fisher_f_distribution : public std::fisher_f_distribution { - using rep = Q::rep; - using base = std::fisher_f_distribution; + using rep = Q::rep; + using base = std::fisher_f_distribution; fisher_f_distribution() : base() {} fisher_f_distribution(const rep& m, const rep& n) : base(m, n) {} @@ -414,8 +414,8 @@ struct fisher_f_distribution : public std::fisher_f_distribution requires std::floating_point struct student_t_distribution : public std::student_t_distribution { - using rep = Q::rep; - using base = std::student_t_distribution; + using rep = Q::rep; + using base = std::student_t_distribution; student_t_distribution() : base() {} explicit student_t_distribution(const rep& n) : base(n) {} @@ -433,8 +433,8 @@ struct student_t_distribution : public std::student_t_distribution requires std::integral struct discrete_distribution : public std::discrete_distribution { - using rep = Q::rep; - using base = std::discrete_distribution; + using rep = Q::rep; + using base = std::discrete_distribution; discrete_distribution() : base() {} @@ -464,8 +464,8 @@ struct discrete_distribution : public std::discrete_distribution requires std::floating_point class piecewise_constant_distribution : public std::piecewise_constant_distribution { - using rep = Q::rep; - using base = std::piecewise_constant_distribution; + using rep = Q::rep; + using base = std::piecewise_constant_distribution; template piecewise_constant_distribution(const std::vector& i, InputIt first_w) : base(i.cbegin(), i.cend(), first_w) @@ -523,8 +523,8 @@ public: template requires std::floating_point class piecewise_linear_distribution : public std::piecewise_linear_distribution { - using rep = Q::rep; - using base = std::piecewise_linear_distribution; + using rep = Q::rep; + using base = std::piecewise_linear_distribution; template piecewise_linear_distribution(const std::vector& i, InputIt first_w) : base(i.cbegin(), i.cend(), first_w) diff --git a/src/systems/include/mp-units/systems/si/chrono.h b/src/systems/include/mp-units/systems/si/chrono.h index b4ba90be..3001edd0 100644 --- a/src/systems/include/mp-units/systems/si/chrono.h +++ b/src/systems/include/mp-units/systems/si/chrono.h @@ -137,8 +137,8 @@ template QP> requires is_specialization_of, chrono_point_origin_> [[nodiscard]] constexpr auto to_chrono_time_point(const QP& qp) { - using clock = decltype(QP::absolute_point_origin)::clock; - using rep = QP::rep; + using clock = decltype(QP::absolute_point_origin)::clock; + using rep = QP::rep; using ret_type = std::chrono::time_point>; diff --git a/src/systems/include/mp-units/systems/si/math.h b/src/systems/include/mp-units/systems/si/math.h index c91d0df8..80568e37 100644 --- a/src/systems/include/mp-units/systems/si/math.h +++ b/src/systems/include/mp-units/systems/si/math.h @@ -87,7 +87,8 @@ template auto R, template auto R, typename Rep> requires requires(Rep v) { asin(v); } || requires(Rep v) { std::asin(v); } -[[nodiscard]] inline QuantityOf auto asin(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto asin( + const quantity& q) noexcept { using std::asin; if constexpr (!treat_as_floating_point) { @@ -101,7 +102,8 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { acos(v); } || requires(Rep v) { std::acos(v); } -[[nodiscard]] inline QuantityOf auto acos(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto acos( + const quantity& q) noexcept { using std::acos; if constexpr (!treat_as_floating_point) { @@ -115,7 +117,8 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { atan(v); } || requires(Rep v) { std::atan(v); } -[[nodiscard]] inline QuantityOf auto atan(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto atan( + const quantity& q) noexcept { using std::atan; if constexpr (!treat_as_floating_point) { From aebf55c09af91639d93e1bdfad2178cc190ec6b7 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:10:39 +0200 Subject: [PATCH 34/44] Revert "Merge branch 'master-msvc-194-only-lib' into master-msvc-194" This reverts commit e3034c55542a5e569cd44264f2e9921114a10c92, reversing changes made to 8be458b0b753f83091e655037d9f69a2889d339e. --- example/avg_speed.cpp | 12 +- example/capacitor_time_curve.cpp | 2 +- example/clcpp_response.cpp | 4 +- example/currency.cpp | 14 +- example/glide_computer.cpp | 10 +- .../include/glide_computer_lib.h | 2 +- example/hello_units.cpp | 2 +- example/include/geographic.h | 8 +- example/kalman_filter/kalman.h | 16 +- example/measurement.cpp | 2 +- example/spectroscopy_units.cpp | 8 +- example/storage_tank.cpp | 10 +- example/total_energy.cpp | 18 +- example/unmanned_aerial_vehicle.cpp | 1 + src/core/include/mp-units/bits/hacks.h | 2 +- src/core/include/mp-units/bits/type_list.h | 26 +- src/core/include/mp-units/ext/type_traits.h | 12 +- .../mp-units/framework/expression_template.h | 11 +- .../mp-units/framework/quantity_spec.h | 33 +- .../include/mp-units/framework/reference.h | 31 +- src/core/include/mp-units/random.h | 78 +- .../include/mp-units/systems/si/chrono.h | 4 +- .../include/mp-units/systems/si/math.h | 9 +- test/runtime/CMakeLists.txt | 10 +- test/static/chrono_test.cpp | 76 +- test/static/concepts_test.cpp | 242 +++--- test/static/custom_rep_test_min_impl.cpp | 67 +- test/static/dimension_test.cpp | 2 +- test/static/quantity_point_test.cpp | 787 +++++++++--------- test/static/quantity_spec_test.cpp | 4 +- test/static/quantity_test.cpp | 204 ++--- test/static/reference_test.cpp | 6 +- test/static/si_test.cpp | 2 +- test/static/unit_test.cpp | 4 +- 34 files changed, 864 insertions(+), 855 deletions(-) diff --git a/example/avg_speed.cpp b/example/avg_speed.cpp index dc2d24d2..11072bb3 100644 --- a/example/avg_speed.cpp +++ b/example/avg_speed.cpp @@ -45,26 +45,26 @@ namespace { using namespace mp_units; -constexpr quantity fixed_int_si_avg_speed(quantity d, - quantity t) +constexpr quantity fixed_int_si_avg_speed(quantity<(si::metre), int> d, + quantity<(si::second), int> t) { return d / t; } -constexpr quantity fixed_double_si_avg_speed(quantity d, quantity t) +constexpr quantity fixed_double_si_avg_speed(quantity<(si::metre)> d, quantity<(si::second)> t) { return d / t; } -constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) +constexpr QuantityOf<(isq::speed)> auto avg_speed(QuantityOf<(isq::length)> auto d, QuantityOf<(isq::time)> auto t) { return d / t; } -template D, QuantityOf T, QuantityOf V> +template D, QuantityOf<(isq::time)> T, QuantityOf<(isq::speed)> V> void print_result(D distance, T duration, V speed) { - const auto result_in_kmph = speed.force_in(si::kilo / non_si::hour); + const auto result_in_kmph = speed.force_in((si::kilo<(si::metre)> / non_si::hour)); std::cout << "Average speed of a car that makes " << distance << " in " << duration << " is " << result_in_kmph << ".\n"; } diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp index 4cf363fe..2f2f7fdb 100644 --- a/example/capacitor_time_curve.cpp +++ b/example/capacitor_time_curve.cpp @@ -48,7 +48,7 @@ int main() constexpr auto RR = isq::resistance(4.7 * si::kilo); for (auto tt = 0 * ms; tt <= 50 * ms; ++tt) { - const QuantityOf auto Vt = V0 * exp(dimensionless(-tt / (RR * CC))); + const QuantityOf<(isq::voltage)> auto Vt = V0 * exp(dimensionless(-tt / (RR * CC))); // TODO try to make the below work instead // const QuantityOf auto Vt = V0 * exp(-tt / (RR * CC)); diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index 42ed6d0b..9a74de52 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -44,8 +44,8 @@ void simple_quantities() using namespace mp_units::si; using namespace mp_units::international; - using distance = quantity]>; - using duration = quantity; + using distance = quantity<(isq::distance[kilo])>; + using duration = quantity<(isq::duration[second])>; constexpr distance km = 1. * kilo; constexpr distance miles = 1. * mile; diff --git a/example/currency.cpp b/example/currency.cpp index 6f280659..0eb46040 100644 --- a/example/currency.cpp +++ b/example/currency.cpp @@ -90,11 +90,11 @@ template #endif -template auto To, ReferenceOf auto From, typename Rep> -quantity exchange_to(quantity q) -{ - return static_cast(exchange_rate() * q.numerical_value()) * To; -} +// template auto To, ReferenceOf auto From, typename Rep> +// quantity exchange_to(quantity q) +// { +// return static_cast(exchange_rate() * q.numerical_value()) * To; +// } template auto To, ReferenceOf auto From, auto PO, typename Rep> quantity_point exchange_to(quantity_point q) @@ -107,8 +107,8 @@ int main() { using namespace unit_symbols; - const quantity_point price_usd{100 * USD}; - const quantity_point price_euro = exchange_to(price_usd); + const mp_units::quantity_point price_usd{100 * USD}; + const mp_units::quantity_point price_euro = exchange_to(price_usd); std::cout << price_usd.quantity_from_zero() << " -> " << price_euro.quantity_from_zero() << "\n"; // std::cout << price_usd.quantity_from_zero() + price_euro.quantity_from_zero() << "\n"; // does diff --git a/example/glide_computer.cpp b/example/glide_computer.cpp index 133a7713..f06062fe 100644 --- a/example/glide_computer.cpp +++ b/example/glide_computer.cpp @@ -169,7 +169,7 @@ void example() const auto gliders = get_gliders(); const auto waypoints = get_waypoints(); const auto weather_conditions = get_weather_conditions(); - const task t = {waypoints[0], waypoints[1], waypoints[0]}; + const task glider_task = {waypoints[0], waypoints[1], waypoints[0]}; const aircraft_tow tow = {400 * m, 1.6 * m / s}; const timestamp start_time(std::chrono::system_clock::now()); @@ -177,16 +177,16 @@ void example() print(gliders); print(waypoints); print(weather_conditions); - print(t); + print(glider_task); print(tow); - for (const auto& g : gliders) { + for (const auto& glider : gliders) { for (const auto& c : weather_conditions) { - const std::string txt = "Scenario: Glider = " + g.name + ", Weather = " + c.first; + const std::string txt = "Scenario: Glider = " + glider.name + ", Weather = " + c.first; std::cout << txt << "\n"; std::cout << MP_UNITS_STD_FMT::format("{0:=^{1}}\n\n", "", txt.size()); - estimate(start_time, g, c.second, t, sfty, tow); + estimate(start_time, glider, c.second, glider_task, sfty, tow); std::cout << "\n\n"; } diff --git a/example/glide_computer_lib/include/glide_computer_lib.h b/example/glide_computer_lib/include/glide_computer_lib.h index 5e2ac4db..e8fafbf3 100644 --- a/example/glide_computer_lib/include/glide_computer_lib.h +++ b/example/glide_computer_lib/include/glide_computer_lib.h @@ -90,7 +90,7 @@ struct glider { std::array polar; }; -constexpr mp_units::QuantityOf auto glide_ratio(const glider::polar_point& polar) +constexpr mp_units::QuantityOf<(mp_units::dimensionless)> auto glide_ratio(const glider::polar_point& polar) { return polar.v / -polar.climb; } diff --git a/example/hello_units.cpp b/example/hello_units.cpp index e635bc25..95b5e6d6 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -45,7 +45,7 @@ import mp_units; using namespace mp_units; -constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) +constexpr QuantityOf<(isq::speed)> auto avg_speed(QuantityOf<(isq::length)> auto d, QuantityOf<(isq::time)> auto t) { return d / t; } diff --git a/example/include/geographic.h b/example/include/geographic.h index ba26b3f1..4f7ca94a 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -79,10 +79,10 @@ inline constexpr struct prime_meridian final : mp_units::absolute_point_origin -using latitude = mp_units::quantity_point>; +using latitude = mp_units::quantity_point<(mp_units::si::degree), equator, ranged_representation>; template -using longitude = mp_units::quantity_point>; +using longitude = mp_units::quantity_point<(mp_units::si::degree), prime_meridian, ranged_representation>; template std::basic_ostream& operator<<(std::basic_ostream& os, const latitude& lat) @@ -176,7 +176,7 @@ template distance spherical_distance(position from, position to) { using namespace mp_units; - constexpr quantity earth_radius = 6'371 * isq::radius[si::kilo]; + constexpr quantity earth_radius = 6'371 * isq::radius[si::kilo<(si::metre)>]; using si::sin, si::cos, si::asin, si::acos; @@ -193,7 +193,7 @@ distance spherical_distance(position from, position to) // const auto central_angle = 2 * asin(sqrt(0.5 - cos(to_lat - from_lat) / 2 + cos(from_lat) * cos(to_lat) * (1 // - cos(lon2_rad - from_lon)) / 2)); - return quantity_cast(earth_radius * central_angle); + return quantity_cast<(isq::distance)>(earth_radius * central_angle); } else { // the haversine formula const quantity sin_lat = sin((to_lat - from_lat) / 2); diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index 90d0d506..80179790 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -116,15 +116,15 @@ template } // state update -template K> +template K> requires(implicitly_convertible(QM::quantity_spec, QP::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, K gain) { return system_state{get<0>(predicted) + gain * (measured - get<0>(predicted))}; } -template K, - mp_units::QuantityOf T> +template K, + mp_units::QuantityOf<(mp_units::isq::time)> T> requires(implicitly_convertible(QM::quantity_spec, QP1::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, std::array gain, T interval) @@ -135,7 +135,7 @@ template K, mp_units::QuantityOf T> + mp_units::QuantityOf<(mp_units::dimensionless)> K, mp_units::QuantityOf<(mp_units::isq::time)> T> requires(implicitly_convertible(QM::quantity_spec, QP1::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, std::array gain, T interval) @@ -147,13 +147,13 @@ template K> +template K> [[nodiscard]] constexpr Q covariance_update(Q uncertainty, K gain) { return (1 * mp_units::one - gain) * uncertainty; } -template K> +template K> [[nodiscard]] constexpr system_state_estimate state_estimate_update( const system_state_estimate& previous, QP measurement, K gain) { @@ -162,7 +162,7 @@ template T> +template T> [[nodiscard]] constexpr system_state state_extrapolation(const system_state& estimated, T interval) { auto to_quantity = [](const auto& qp) { return qp.quantity_ref_from(qp.point_origin); }; @@ -171,7 +171,7 @@ template T return system_state{qp1, qp2}; } -template T> +template T> [[nodiscard]] constexpr system_state state_extrapolation(const system_state& estimated, T interval) { diff --git a/example/measurement.cpp b/example/measurement.cpp index b0cf594b..d7650c21 100644 --- a/example/measurement.cpp +++ b/example/measurement.cpp @@ -151,7 +151,7 @@ void example() const auto acceleration = isq::acceleration(measurement{9.8, 0.1} * m / s2); const auto time = measurement{1.2, 0.1} * s; - const QuantityOf auto velocity = acceleration * time; + const QuantityOf<(isq::velocity)> auto velocity = acceleration * time; std::cout << acceleration << " * " << time << " = " << velocity << " = " << velocity.in(km / h) << '\n'; const auto length = measurement{123., 1.} * m; diff --git a/example/spectroscopy_units.cpp b/example/spectroscopy_units.cpp index 3fce6a8b..d618b3b3 100644 --- a/example/spectroscopy_units.cpp +++ b/example/spectroscopy_units.cpp @@ -54,8 +54,8 @@ constexpr auto h = 1 * si::si2019::planck_constant; constexpr auto kb = 1 * si::si2019::boltzmann_constant; // prints quantities in the resulting unit -template T1, QuantityOf T2, QuantityOf T3, - QuantityOf T4, QuantityOf T5> +template T1, QuantityOf<(isq::wavenumber)> T2, QuantityOf<(isq::frequency)> T3, + QuantityOf<(isq::thermodynamic_temperature)> T4, QuantityOf<(isq::wavelength)> T5> void print_line(const std::tuple& t) { std::cout << MP_UNITS_STD_FMT::format( @@ -65,8 +65,8 @@ void print_line(const std::tuple& t) // prints quantities in semi-SI units // (eV is not an official SI unit) -template T1, QuantityOf T2, QuantityOf T3, - QuantityOf T4, QuantityOf T5> +template T1, QuantityOf<(isq::wavenumber)> T2, QuantityOf<(isq::frequency)> T3, + QuantityOf<(isq::thermodynamic_temperature)> T4, QuantityOf<(isq::wavelength)> T5> void print_line_si(const std::tuple& t) { std::cout << MP_UNITS_STD_FMT::format( diff --git a/example/storage_tank.cpp b/example/storage_tank.cpp index 86bc32ff..44b24738 100644 --- a/example/storage_tank.cpp +++ b/example/storage_tank.cpp @@ -77,10 +77,10 @@ public: density_ = density; } - [[nodiscard]] constexpr QuantityOf auto filled_weight() const + [[nodiscard]] constexpr QuantityOf<(isq::weight)> auto filled_weight() const { const auto volume = isq::volume(base_ * height_); // TODO check if we can remove that cast - const QuantityOf auto mass = density_ * volume; + const QuantityOf<(isq::mass)> auto mass = density_ * volume; return isq::weight(mass * g); } @@ -130,9 +130,9 @@ int main() const quantity spare_capacity = tank.spare_capacity(measured_mass); const quantity filled_weight = tank.filled_weight(); - const QuantityOf auto input_flow_rate = measured_mass / fill_time; - const QuantityOf auto float_rise_rate = fill_level / fill_time; - const QuantityOf auto fill_time_left = (height / fill_level - 1 * one) * fill_time; + const QuantityOf<(isq::mass_change_rate)> auto input_flow_rate = measured_mass / fill_time; + const QuantityOf<(isq::speed)> auto float_rise_rate = fill_level / fill_time; + const QuantityOf<(isq::time)> auto fill_time_left = (height / fill_level - 1 * one) * fill_time; const quantity fill_ratio = fill_level / height; diff --git a/example/total_energy.cpp b/example/total_energy.cpp index 75416bb7..28963f6b 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -45,8 +45,8 @@ namespace { using namespace mp_units; -QuantityOf auto total_energy(QuantityOf auto p, QuantityOf auto m, - QuantityOf auto c) +QuantityOf<(isq::mechanical_energy)> auto total_energy(QuantityOf<(isq::momentum)> auto p, + QuantityOf<(isq::mass)> auto m, QuantityOf<(isq::speed)> auto c) { return isq::mechanical_energy(sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c)))); } @@ -59,19 +59,19 @@ void si_example() const quantity c2 = pow<2>(c); const quantity p1 = isq::momentum(4. * GeV / c); - const QuantityOf auto m1 = 3. * GeV / c2; - const quantity E = total_energy(p1, m1, c); + const QuantityOf<(isq::mass)> auto m1 = 3. * GeV / c2; + const quantity E1 = total_energy(p1, m1, c); std::cout << "\n*** SI units (c = " << c << " = " << c.in(si::metre / s) << ") ***\n"; std::cout << "\n[in `GeV` and `c`]\n" << "p = " << p1 << "\n" << "m = " << m1 << "\n" - << "E = " << E << "\n"; + << "E = " << E1 << "\n"; const quantity p2 = p1.in(GeV / (m / s)); - const quantity m2 = m1.in(GeV / pow<2>(m / s)); - const quantity E2 = total_energy(p2, m2, c).in(GeV); + const quantity metre2 = m1.in(GeV / pow<2>(m / s)); + const quantity E2 = total_energy(p2, metre2, c).in(GeV); std::cout << "\n[in `GeV`]\n" << "p = " << p2 << "\n" @@ -79,8 +79,8 @@ void si_example() << "E = " << E2 << "\n"; const quantity p3 = p1.in(kg * m / s); - const quantity m3 = m1.in(kg); - const quantity E3 = total_energy(p3, m3, c).in(J); + const quantity metre3 = m1.in(kg); + const quantity E3 = total_energy(p3, metre3, c).in(J); std::cout << "\n[in SI base units]\n" << "p = " << p3 << "\n" diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index 064e8055..9cb32bfc 100644 --- a/example/unmanned_aerial_vehicle.cpp +++ b/example/unmanned_aerial_vehicle.cpp @@ -70,6 +70,7 @@ constexpr const char* to_text(earth_gravity_model m) return "EGM2008-1"; } assert(false && "unsupported enum value"); + return "unsupported enum value"; } template diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 0099be3d..4aec2a8d 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -124,7 +124,7 @@ inline constexpr from_range_t from_range{}; #else #define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X -#define MP_UNITS_EXPRESSION_WORKAROUND(x) x +#define MP_UNITS_EXPRESSION_WORKAROUND(x) x #define MP_UNITS_IS_VALUE_WORKAROUND(x) x #define MP_UNITS_IS_CONST_EXPR_WORKAROUND(x) x diff --git a/src/core/include/mp-units/bits/type_list.h b/src/core/include/mp-units/bits/type_list.h index 636c1df1..61708944 100644 --- a/src/core/include/mp-units/bits/type_list.h +++ b/src/core/include/mp-units/bits/type_list.h @@ -68,7 +68,7 @@ struct type_list_map_impl, To> { }; template typename To> -using type_list_map = type_list_map_impl::type; +using type_list_map = type_list_map_impl::type; // element @@ -105,7 +105,7 @@ struct type_list_front_impl> { }; template -using type_list_front = type_list_front_impl::type; +using type_list_front = type_list_front_impl::type; // back template @@ -121,7 +121,7 @@ struct type_list_push_front_impl, NewTypes...> { }; template -using type_list_push_front = type_list_push_front_impl::type; +using type_list_push_front = type_list_push_front_impl::type; // push_back template @@ -133,7 +133,7 @@ struct type_list_push_back_impl, NewTypes...> { }; template -using type_list_push_back = type_list_push_back_impl::type; +using type_list_push_back = type_list_push_back_impl::type; // join template @@ -143,11 +143,11 @@ struct type_list_join_impl { template typename List, typename... First, typename... Second, typename... Rest> struct type_list_join_impl, List, Rest...> { - using type = type_list_join_impl, Rest...>::type; + using type = type_list_join_impl, Rest...>::type; }; template -using type_list_join = type_list_join_impl::type; +using type_list_join = type_list_join_impl::type; // split template @@ -195,19 +195,19 @@ template typename List, typename Lhs1, typename... LhsRest template typename Pred> requires Pred::value struct type_list_merge_sorted_impl, List, Pred> { - using type = type_list_push_front_impl< + using type = type_list_push_front_impl< typename type_list_merge_sorted_impl, List, Pred>::type, Lhs1>::type; }; template typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest, template typename Pred> struct type_list_merge_sorted_impl, List, Pred> { - using type = type_list_push_front_impl< + using type = type_list_push_front_impl< typename type_list_merge_sorted_impl, List, Pred>::type, Rhs1>::type; }; template typename Pred> -using type_list_merge_sorted = type_list_merge_sorted_impl::type; +using type_list_merge_sorted = type_list_merge_sorted_impl::type; // sort template typename Pred> @@ -227,13 +227,13 @@ template typename List, typename... Types, template, Pred> { using types = List; using split = type_list_split_half>; - using sorted_left = type_list_sort_impl::type; - using sorted_right = type_list_sort_impl::type; - using type = type_list_merge_sorted_impl::type; + using sorted_left = type_list_sort_impl::type; + using sorted_right = type_list_sort_impl::type; + using type = type_list_merge_sorted_impl::type; }; template typename Pred> -using type_list_sort = type_list_sort_impl::type; +using type_list_sort = type_list_sort_impl::type; } // namespace mp_units::detail diff --git a/src/core/include/mp-units/ext/type_traits.h b/src/core/include/mp-units/ext/type_traits.h index 2ee78e2a..77f0267b 100644 --- a/src/core/include/mp-units/ext/type_traits.h +++ b/src/core/include/mp-units/ext/type_traits.h @@ -56,7 +56,7 @@ struct conditional_impl { MP_UNITS_EXPORT_BEGIN template -using conditional = detail::conditional_impl::template type; +using conditional = detail::conditional_impl::template type; // is_same template @@ -98,7 +98,7 @@ namespace detail { template struct get_value_type { - using type = T::value_type; + using type = T::value_type; }; template @@ -111,13 +111,13 @@ struct get_element_type { template requires requires { typename T::value_type; } || requires { typename T::element_type; } struct wrapped_type { - using type = + using type = conditional, detail::get_element_type>::type; }; template requires requires { typename T::value_type; } || requires { typename T::element_type; } -using wrapped_type_t = wrapped_type::type; +using wrapped_type_t = wrapped_type::type; template struct value_type { @@ -127,11 +127,11 @@ struct value_type { template requires requires { typename wrapped_type_t; } struct value_type { - using type = wrapped_type_t; + using type = wrapped_type_t; }; template -using value_type_t = value_type::type; +using value_type_t = value_type::type; template concept one_of = (false || ... || std::same_as); diff --git a/src/core/include/mp-units/framework/expression_template.h b/src/core/include/mp-units/framework/expression_template.h index 45d3d4b6..6b5836ff 100644 --- a/src/core/include/mp-units/framework/expression_template.h +++ b/src/core/include/mp-units/framework/expression_template.h @@ -122,7 +122,7 @@ struct expr_type_impl> : std::type_identity {}; } // namespace detail template -using expr_type = detail::expr_type_impl::type; +using expr_type = detail::expr_type_impl::type; namespace detail { @@ -182,24 +182,25 @@ struct expr_consolidate_impl> { template requires(!is_specialization_of_power) struct expr_consolidate_impl> { - using type = expr_consolidate_impl, Rest...>>::type; + using type = expr_consolidate_impl, Rest...>>::type; }; // replaces the instance of a type and a power of it with one with incremented power template struct expr_consolidate_impl, Rest...>> { - using type = expr_consolidate_impl::exponent + 1>, Rest...>>::type; + using type = + expr_consolidate_impl::exponent + 1>, Rest...>>::type; }; // accumulates the powers of instances of the same type (removes the element in case the accumulation result is `0`) template struct expr_consolidate_impl, power, Rest...>> { static constexpr ratio r = power::exponent + power::exponent; - using type = expr_consolidate_impl, Rest...>>::type; + using type = expr_consolidate_impl, Rest...>>::type; }; template -using expr_consolidate = expr_consolidate_impl::type; +using expr_consolidate = expr_consolidate_impl::type; /** diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 89a35c8f..934aa9b5 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -1343,22 +1343,19 @@ template }; if constexpr ((NamedQuantitySpec && NamedQuantitySpec) || - get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) == - get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))) + get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) == get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))) return convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)); else if constexpr (get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) > get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))) - return exploded_kind_result( - convertible_impl(get_kind_tree_root(explode( - MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) - .quantity), - MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))); + return exploded_kind_result(convertible_impl( + get_kind_tree_root( + explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)).quantity), + MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))); else - return exploded_kind_result( - convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), - get_kind_tree_root(explode( - MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)) - .quantity))); + return exploded_kind_result(convertible_impl( + MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), + get_kind_tree_root( + explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)).quantity))); } template @@ -1376,12 +1373,10 @@ template else if constexpr (get_complexity(From{}) != get_complexity(To{})) { if constexpr (get_complexity(From{}) > get_complexity(To{})) return convertible_impl( - explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)) - .quantity, + explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)).quantity, MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); else { - auto res = - explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), res.quantity)); } } @@ -1414,8 +1409,7 @@ template auto eq = explode_to_equation(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); return min(eq.result, convertible_impl(res.quantity, eq.equation)); } else - return are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), - MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + return are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); } else if constexpr (DerivedQuantitySpec) { auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); if constexpr (NamedQuantitySpec) @@ -1423,8 +1417,7 @@ template else if constexpr (requires { MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)._equation_; }) return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)._equation_, res.quantity)); else - return min(res.result, are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), - MP_UNITS_IS_CONST_EXPR_WORKAROUND(to))); + return min(res.result, are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to))); } // NOLINTEND(bugprone-branch-clone) return no; diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index 7dba6475..5a5f8262 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -87,48 +87,46 @@ struct reference { } template - [[nodiscard]] friend consteval detail::reference_t + [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} * Q2{}), MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> operator*(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t<(MP_UNITS_EXPRESSION_WORKAROUND(Q{} * get_quantity_spec(U2{}))), - MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> + [[nodiscard]] friend consteval detail::reference_t<( MP_UNITS_EXPRESSION_WORKAROUND(Q{} * get_quantity_spec(U2{}))), + MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> operator*(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t + [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) * Q{}), + MP_UNITS_EXPRESSION_WORKAROUND(U1{} * U{})> operator*(U1, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t + [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} / Q2{}), MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})> operator/(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t + [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} / get_quantity_spec(U2{})), + MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})> operator/(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t + [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) / Q{}), + MP_UNITS_EXPRESSION_WORKAROUND(U1{} / U{})> operator/(U1, reference) { return {}; @@ -293,11 +291,10 @@ template } -> Unit; } { - return detail::reference_t{}; + return detail::reference_t< + common_quantity_spec(get_quantity_spec(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r1)), get_quantity_spec(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r2)), + get_quantity_spec(rest)...), + common_unit(get_unit(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r1)), get_unit(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r2)), get_unit(rest)...)>{}; } MP_UNITS_EXPORT_END diff --git a/src/core/include/mp-units/random.h b/src/core/include/mp-units/random.h index 5da89966..05251f3f 100644 --- a/src/core/include/mp-units/random.h +++ b/src/core/include/mp-units/random.h @@ -61,7 +61,7 @@ std::vector bl_qty_to_rep(std::initializer_list& bl) template std::vector fw_bl_pwc(std::initializer_list& bl, UnaryOperation fw) { - using rep = Q::rep; + using rep = Q::rep; std::vector w_bl; w_bl.reserve(bl.size()); for (const Q& qty : bl) { @@ -93,8 +93,8 @@ MP_UNITS_EXPORT_BEGIN template requires std::integral struct uniform_int_distribution : public std::uniform_int_distribution { - using rep = Q::rep; - using base = std::uniform_int_distribution; + using rep = Q::rep; + using base = std::uniform_int_distribution; uniform_int_distribution() : base() {} uniform_int_distribution(const Q& a, const Q& b) : @@ -118,8 +118,8 @@ struct uniform_int_distribution : public std::uniform_int_distribution requires std::floating_point struct uniform_real_distribution : public std::uniform_real_distribution { - using rep = Q::rep; - using base = std::uniform_real_distribution; + using rep = Q::rep; + using base = std::uniform_real_distribution; uniform_real_distribution() : base() {} uniform_real_distribution(const Q& a, const Q& b) : @@ -143,8 +143,8 @@ struct uniform_real_distribution : public std::uniform_real_distribution requires std::integral struct binomial_distribution : public std::binomial_distribution { - using rep = Q::rep; - using base = std::binomial_distribution; + using rep = Q::rep; + using base = std::binomial_distribution; binomial_distribution() : base() {} binomial_distribution(const Q& t, double p) : base(t.numerical_value_ref_in(Q::unit), p) {} @@ -164,8 +164,8 @@ struct binomial_distribution : public std::binomial_distribution requires std::integral struct negative_binomial_distribution : public std::negative_binomial_distribution { - using rep = Q::rep; - using base = std::negative_binomial_distribution; + using rep = Q::rep; + using base = std::negative_binomial_distribution; negative_binomial_distribution() : base() {} negative_binomial_distribution(const Q& k, double p) : base(k.numerical_value_ref_in(Q::unit), p) {} @@ -185,8 +185,8 @@ struct negative_binomial_distribution : public std::negative_binomial_distributi template requires std::integral struct geometric_distribution : public std::geometric_distribution { - using rep = Q::rep; - using base = std::geometric_distribution; + using rep = Q::rep; + using base = std::geometric_distribution; geometric_distribution() : base() {} explicit geometric_distribution(double p) : base(p) {} @@ -204,8 +204,8 @@ struct geometric_distribution : public std::geometric_distribution requires std::integral struct poisson_distribution : public std::poisson_distribution { - using rep = Q::rep; - using base = std::poisson_distribution; + using rep = Q::rep; + using base = std::poisson_distribution; poisson_distribution() : base() {} explicit poisson_distribution(double p) : base(p) {} @@ -223,8 +223,8 @@ struct poisson_distribution : public std::poisson_distribution template requires std::floating_point struct exponential_distribution : public std::exponential_distribution { - using rep = Q::rep; - using base = std::exponential_distribution; + using rep = Q::rep; + using base = std::exponential_distribution; exponential_distribution() : base() {} explicit exponential_distribution(const rep& lambda) : base(lambda) {} @@ -242,8 +242,8 @@ struct exponential_distribution : public std::exponential_distribution requires std::floating_point struct gamma_distribution : public std::gamma_distribution { - using rep = Q::rep; - using base = std::gamma_distribution; + using rep = Q::rep; + using base = std::gamma_distribution; gamma_distribution() : base() {} gamma_distribution(const rep& alpha, const rep& beta) : base(alpha, beta) {} @@ -261,8 +261,8 @@ struct gamma_distribution : public std::gamma_distribution { template requires std::floating_point struct weibull_distribution : public std::weibull_distribution { - using rep = Q::rep; - using base = std::weibull_distribution; + using rep = Q::rep; + using base = std::weibull_distribution; weibull_distribution() : base() {} weibull_distribution(const rep& a, const rep& b) : base(a, b) {} @@ -280,8 +280,8 @@ struct weibull_distribution : public std::weibull_distribution template requires std::floating_point struct extreme_value_distribution : public std::extreme_value_distribution { - using rep = Q::rep; - using base = std::extreme_value_distribution; + using rep = Q::rep; + using base = std::extreme_value_distribution; extreme_value_distribution() : base() {} extreme_value_distribution(const Q& a, const rep& b) : base(a.numerical_value_ref_in(Q::unit), b) {} @@ -301,8 +301,8 @@ struct extreme_value_distribution : public std::extreme_value_distribution requires std::floating_point struct normal_distribution : public std::normal_distribution { - using rep = Q::rep; - using base = std::normal_distribution; + using rep = Q::rep; + using base = std::normal_distribution; normal_distribution() : base() {} normal_distribution(const Q& mean, const Q& stddev) : @@ -326,8 +326,8 @@ struct normal_distribution : public std::normal_distribution { template requires std::floating_point struct lognormal_distribution : public std::lognormal_distribution { - using rep = Q::rep; - using base = std::lognormal_distribution; + using rep = Q::rep; + using base = std::lognormal_distribution; lognormal_distribution() : base() {} lognormal_distribution(const Q& m, const Q& s) : @@ -351,8 +351,8 @@ struct lognormal_distribution : public std::lognormal_distribution requires std::floating_point struct chi_squared_distribution : public std::chi_squared_distribution { - using rep = Q::rep; - using base = std::chi_squared_distribution; + using rep = Q::rep; + using base = std::chi_squared_distribution; chi_squared_distribution() : base() {} explicit chi_squared_distribution(const rep& n) : base(n) {} @@ -370,8 +370,8 @@ struct chi_squared_distribution : public std::chi_squared_distribution requires std::floating_point struct cauchy_distribution : public std::cauchy_distribution { - using rep = Q::rep; - using base = std::cauchy_distribution; + using rep = Q::rep; + using base = std::cauchy_distribution; cauchy_distribution() : base() {} cauchy_distribution(const Q& a, const Q& b) : @@ -395,8 +395,8 @@ struct cauchy_distribution : public std::cauchy_distribution { template requires std::floating_point struct fisher_f_distribution : public std::fisher_f_distribution { - using rep = Q::rep; - using base = std::fisher_f_distribution; + using rep = Q::rep; + using base = std::fisher_f_distribution; fisher_f_distribution() : base() {} fisher_f_distribution(const rep& m, const rep& n) : base(m, n) {} @@ -414,8 +414,8 @@ struct fisher_f_distribution : public std::fisher_f_distribution requires std::floating_point struct student_t_distribution : public std::student_t_distribution { - using rep = Q::rep; - using base = std::student_t_distribution; + using rep = Q::rep; + using base = std::student_t_distribution; student_t_distribution() : base() {} explicit student_t_distribution(const rep& n) : base(n) {} @@ -433,8 +433,8 @@ struct student_t_distribution : public std::student_t_distribution requires std::integral struct discrete_distribution : public std::discrete_distribution { - using rep = Q::rep; - using base = std::discrete_distribution; + using rep = Q::rep; + using base = std::discrete_distribution; discrete_distribution() : base() {} @@ -464,8 +464,8 @@ struct discrete_distribution : public std::discrete_distribution requires std::floating_point class piecewise_constant_distribution : public std::piecewise_constant_distribution { - using rep = Q::rep; - using base = std::piecewise_constant_distribution; + using rep = Q::rep; + using base = std::piecewise_constant_distribution; template piecewise_constant_distribution(const std::vector& i, InputIt first_w) : base(i.cbegin(), i.cend(), first_w) @@ -523,8 +523,8 @@ public: template requires std::floating_point class piecewise_linear_distribution : public std::piecewise_linear_distribution { - using rep = Q::rep; - using base = std::piecewise_linear_distribution; + using rep = Q::rep; + using base = std::piecewise_linear_distribution; template piecewise_linear_distribution(const std::vector& i, InputIt first_w) : base(i.cbegin(), i.cend(), first_w) diff --git a/src/systems/include/mp-units/systems/si/chrono.h b/src/systems/include/mp-units/systems/si/chrono.h index 0ded9689..c3fb9707 100644 --- a/src/systems/include/mp-units/systems/si/chrono.h +++ b/src/systems/include/mp-units/systems/si/chrono.h @@ -137,8 +137,8 @@ template QP> requires is_specialization_of, chrono_point_origin_> [[nodiscard]] constexpr auto to_chrono_time_point(const QP& qp) { - using clock = decltype(QP::absolute_point_origin)::clock; - using rep = QP::rep; + using clock = decltype(QP::absolute_point_origin)::clock; + using rep = QP::rep; using ret_type = std::chrono::time_point>; diff --git a/src/systems/include/mp-units/systems/si/math.h b/src/systems/include/mp-units/systems/si/math.h index 80568e37..c91d0df8 100644 --- a/src/systems/include/mp-units/systems/si/math.h +++ b/src/systems/include/mp-units/systems/si/math.h @@ -87,8 +87,7 @@ template auto R, template auto R, typename Rep> requires requires(Rep v) { asin(v); } || requires(Rep v) { std::asin(v); } -[[nodiscard]] inline QuantityOf auto asin( - const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto asin(const quantity& q) noexcept { using std::asin; if constexpr (!treat_as_floating_point) { @@ -102,8 +101,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { acos(v); } || requires(Rep v) { std::acos(v); } -[[nodiscard]] inline QuantityOf auto acos( - const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto acos(const quantity& q) noexcept { using std::acos; if constexpr (!treat_as_floating_point) { @@ -117,8 +115,7 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { atan(v); } || requires(Rep v) { std::atan(v); } -[[nodiscard]] inline QuantityOf auto atan( - const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto atan(const quantity& q) noexcept { using std::atan; if constexpr (!treat_as_floating_point) { diff --git a/test/runtime/CMakeLists.txt b/test/runtime/CMakeLists.txt index d79ed54b..70e13650 100644 --- a/test/runtime/CMakeLists.txt +++ b/test/runtime/CMakeLists.txt @@ -37,11 +37,11 @@ if(${projectPrefix}BUILD_CXX_MODULES) endif() target_link_libraries(unit_tests_runtime PRIVATE mp-units::mp-units Catch2::Catch2WithMain) -if(${projectPrefix}DEV_BUILD_LA) - find_package(wg21_linear_algebra REQUIRED) - target_sources(unit_tests_runtime PRIVATE linear_algebra_test.cpp) - target_link_libraries(unit_tests_runtime PRIVATE wg21_linear_algebra::wg21_linear_algebra) -endif() +# if(${projectPrefix}DEV_BUILD_LA) +# find_package(wg21_linear_algebra REQUIRED) +# target_sources(unit_tests_runtime PRIVATE linear_algebra_test.cpp) +# target_link_libraries(unit_tests_runtime PRIVATE wg21_linear_algebra::wg21_linear_algebra) +# endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options( diff --git a/test/static/chrono_test.cpp b/test/static/chrono_test.cpp index 9f3b1901..2785041f 100644 --- a/test/static/chrono_test.cpp +++ b/test/static/chrono_test.cpp @@ -57,41 +57,43 @@ static_assert(!QuantityPoint); // construction - same rep type static_assert( - std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); + std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); static_assert( - std::constructible_from, sys_seconds>); + !std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); static_assert( - !std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(!std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(!std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert(!std::constructible_from, sys_seconds>); -static_assert(!std::convertible_to>); + std::constructible_from, sys_seconds>); +static_assert( + !std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(!std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(!std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert( + !std::constructible_from, sys_seconds>); +static_assert(!std::convertible_to>); // construction - different rep type (integral to a floating-point) -static_assert(std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); static_assert(quantity{1s} == 1 * s); static_assert(quantity{1s} == 1 * s); @@ -107,13 +109,13 @@ static_assert(is_of_type>); -static_assert(std::convertible_to, std::chrono::seconds>); -static_assert(std::constructible_from>); -static_assert(std::convertible_to, std::chrono::hours>); + std::constructible_from>); +static_assert(std::convertible_to, std::chrono::seconds>); +static_assert(std::constructible_from>); +static_assert(std::convertible_to, std::chrono::hours>); static_assert( - std::constructible_from>); -static_assert(std::convertible_to, sys_seconds>); + std::constructible_from>); +static_assert(std::convertible_to, sys_seconds>); // units mapping static_assert(quantity{1ns} == 1 * ns); diff --git a/test/static/concepts_test.cpp b/test/static/concepts_test.cpp index c67ff710..9564ed22 100644 --- a/test/static/concepts_test.cpp +++ b/test/static/concepts_test.cpp @@ -83,7 +83,7 @@ inline constexpr auto speed = isq::length / isq::time; static_assert(QuantitySpec); static_assert(QuantitySpec); static_assert(QuantitySpec); -static_assert(QuantitySpec)>); +static_assert(QuantitySpec)>); static_assert(QuantitySpec); static_assert(QuantitySpec(isq::length))>); static_assert(QuantitySpec); @@ -95,7 +95,7 @@ static_assert(!QuantitySpec); static_assert(detail::NamedQuantitySpec); static_assert(detail::NamedQuantitySpec); static_assert(detail::NamedQuantitySpec); -static_assert(!detail::NamedQuantitySpec)>>); +static_assert(!detail::NamedQuantitySpec)>>); static_assert(!detail::NamedQuantitySpec); static_assert(!detail::NamedQuantitySpec(isq::length))>); static_assert(detail::NamedQuantitySpec); @@ -106,7 +106,7 @@ static_assert(!detail::NamedQuantitySpec); // DerivedQuantitySpec static_assert(!detail::DerivedQuantitySpec); static_assert(!detail::DerivedQuantitySpec); -static_assert(!detail::DerivedQuantitySpec)>); +static_assert(!detail::DerivedQuantitySpec)>); static_assert(!detail::DerivedQuantitySpec); static_assert(detail::DerivedQuantitySpec); static_assert(detail::DerivedQuantitySpec(isq::length))>); @@ -118,7 +118,7 @@ static_assert(!detail::DerivedQuantitySpec); // QuantityKindSpec static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec); -static_assert(detail::QuantityKindSpec)>>); +static_assert(detail::QuantityKindSpec)>>); static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec(isq::length))>); @@ -133,7 +133,7 @@ static_assert(!detail::QuantityKindSpec); // Unit static_assert(Unit); static_assert(Unit); -static_assert(Unit)>); +static_assert(Unit)>); static_assert(Unit); static_assert(Unit); static_assert(Unit); @@ -144,11 +144,11 @@ static_assert(Unit); static_assert(Unit, struct si::second>>); static_assert(Unit>>); static_assert(Unit); -static_assert(!Unit>>); +static_assert(!Unit>>); static_assert(!Unit>); static_assert(!Unit>); -static_assert(!Unit>>); -static_assert(!Unit, si::second>>); +static_assert(!Unit>>); +static_assert(!Unit, (si::second)>>); static_assert(!Unit); static_assert(!Unit); #if MP_UNITS_HOSTED @@ -159,7 +159,7 @@ static_assert(!Unit); static_assert(PrefixableUnit); static_assert(PrefixableUnit); static_assert(!PrefixableUnit); -static_assert(!PrefixableUnit)>); +static_assert(!PrefixableUnit)>); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit * si::second)>); @@ -169,11 +169,11 @@ static_assert(PrefixableUnit); static_assert(!PrefixableUnit, struct si::second>>); static_assert(!PrefixableUnit>>); static_assert(!PrefixableUnit); -static_assert(!PrefixableUnit>>); +static_assert(!PrefixableUnit>>); static_assert(!PrefixableUnit>); static_assert(!PrefixableUnit>); -static_assert(!PrefixableUnit>>); -static_assert(!PrefixableUnit, si::second>>); +static_assert(!PrefixableUnit>>); +static_assert(!PrefixableUnit, (si::second)>>); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit); #if MP_UNITS_HOSTED @@ -184,7 +184,7 @@ static_assert(!PrefixableUnit); static_assert(AssociatedUnit); static_assert(!AssociatedUnit); static_assert(AssociatedUnit); -static_assert(AssociatedUnit)>); +static_assert(AssociatedUnit)>); static_assert(AssociatedUnit); static_assert(AssociatedUnit); static_assert(AssociatedUnit * si::second)>); @@ -194,11 +194,11 @@ static_assert(AssociatedUnit); static_assert(AssociatedUnit, struct si::second>>); static_assert(AssociatedUnit>>); static_assert(AssociatedUnit); -static_assert(!AssociatedUnit>>); +static_assert(!AssociatedUnit>>); static_assert(!AssociatedUnit>); static_assert(!AssociatedUnit>); -static_assert(!AssociatedUnit>>); -static_assert(!AssociatedUnit, si::second>>); +static_assert(!AssociatedUnit>>); +static_assert(!AssociatedUnit, (si::second)>>); static_assert(!AssociatedUnit); static_assert(!AssociatedUnit); #if MP_UNITS_HOSTED @@ -206,19 +206,19 @@ static_assert(!AssociatedUnit); #endif // UnitOf -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); static_assert(!UnitOf); -static_assert(!UnitOf); -static_assert(!UnitOf); +static_assert(!UnitOf); +static_assert(!UnitOf); // Reference static_assert(Reference); @@ -228,32 +228,32 @@ static_assert(Reference); static_assert(Reference); static_assert(!Reference); static_assert(!Reference); -static_assert(!Reference)>); +static_assert(!Reference)>); static_assert(!Reference); static_assert(!Reference); // ReferenceOf -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); static_assert(ReferenceOf); static_assert(ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(!ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(!ReferenceOf); // Representation static_assert(Representation); @@ -278,57 +278,57 @@ static_assert(!RepresentationOf); #endif // Quantity -static_assert(Quantity>); -static_assert(Quantity>); -static_assert(Quantity>); -static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); #if MP_UNITS_HOSTED static_assert(!Quantity); #endif -static_assert(!Quantity>); +static_assert(!Quantity>); static_assert(!Quantity); // QuantityOf -static_assert(QuantityOf, isq::length>); -static_assert(QuantityOf, isq::radius>); -static_assert(!QuantityOf, isq::length>); -static_assert(QuantityOf, isq::length>); -static_assert(!QuantityOf, isq::radius>); -static_assert(QuantityOf, isq::length>); -static_assert(QuantityOf, isq::radius>); -static_assert(!QuantityOf, isq::dim_length>); +static_assert(QuantityOf, (isq::length)>); +static_assert(QuantityOf, (isq::radius)>); +static_assert(!QuantityOf, (isq::length)>); +static_assert(QuantityOf, (isq::length)>); +static_assert(!QuantityOf, (isq::radius)>); +static_assert(QuantityOf, (isq::length)>); +static_assert(QuantityOf, (isq::radius)>); +static_assert(!QuantityOf, (isq::dim_length)>); static_assert(QuantityOf, dimensionless>); static_assert(QuantityOf, dimensionless>); -static_assert(QuantityOf, isq::rotation>); -static_assert(QuantityOf, dimensionless>); -static_assert(QuantityOf, isq::angular_measure>); -static_assert(!QuantityOf, dimensionless>); -static_assert(QuantityOf, isq::angular_measure>); -static_assert(!QuantityOf, dimensionless>); -static_assert(QuantityOf, isq::rotation>); -static_assert(QuantityOf, isq::angular_measure>); -static_assert(!QuantityOf, isq::rotation>); -static_assert(!QuantityOf, isq::angular_measure>); +static_assert(QuantityOf, (isq::rotation)>); +static_assert(QuantityOf, dimensionless>); +static_assert(QuantityOf, (isq::angular_measure)>); +static_assert(!QuantityOf, dimensionless>); +static_assert(QuantityOf, (isq::angular_measure)>); +static_assert(!QuantityOf, dimensionless>); +static_assert(QuantityOf, (isq::rotation)>); +static_assert(QuantityOf, (isq::angular_measure)>); +static_assert(!QuantityOf, (isq::rotation)>); +static_assert(!QuantityOf, (isq::angular_measure)>); // QuantityLike #if MP_UNITS_HOSTED static_assert(QuantityLike); static_assert(QuantityLike); #endif -static_assert(!QuantityLike>); -static_assert(!QuantityLike>); +static_assert(!QuantityLike>); +static_assert(!QuantityLike>); static_assert(!QuantityLike); // QuantityPoint -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); static_assert(!QuantityPoint); -static_assert(!QuantityPoint>); +static_assert(!QuantityPoint>); static_assert(!QuantityPoint); static_assert(!QuantityPoint); #if MP_UNITS_HOSTED @@ -338,35 +338,35 @@ static_assert(!QuantityPoint> static_assert(!QuantityPoint); // QuantityPointOf -static_assert(QuantityPointOf, isq::length>); -static_assert(QuantityPointOf, isq::radius>); -static_assert(QuantityPointOf, isq::length>); -static_assert(!QuantityPointOf, isq::radius>); -static_assert(QuantityPointOf, isq::length>); -static_assert(QuantityPointOf, isq::radius>); -static_assert(QuantityPointOf, isq::length>); -static_assert(QuantityPointOf, isq::radius>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, (isq::length)>); +static_assert(QuantityPointOf, (isq::radius)>); +static_assert(QuantityPointOf, (isq::length)>); +static_assert(!QuantityPointOf, (isq::radius)>); +static_assert(QuantityPointOf, (isq::length)>); +static_assert(QuantityPointOf, (isq::radius)>); +static_assert(QuantityPointOf, (isq::length)>); +static_assert(QuantityPointOf, (isq::radius)>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); // PointOrigin static_assert(PointOrigin); static_assert(PointOrigin); -static_assert(!PointOrigin>); +static_assert(!PointOrigin>); static_assert(!PointOrigin>); -static_assert(!PointOrigin>); -static_assert(!PointOrigin>); -static_assert(!PointOrigin>); +static_assert(!PointOrigin>); +static_assert(!PointOrigin>); +static_assert(!PointOrigin>); static_assert(!PointOrigin); #if MP_UNITS_HOSTED static_assert(!PointOrigin); @@ -375,38 +375,38 @@ static_assert(!PointOrigin>); static_assert(!PointOrigin); // PointOriginFor -static_assert(PointOriginFor); -static_assert(PointOriginFor); -static_assert(!PointOriginFor); -static_assert(PointOriginFor); -static_assert(PointOriginFor); -static_assert(!PointOriginFor); -static_assert(!PointOriginFor, isq::length>); -static_assert(!PointOriginFor, isq::radius>); -static_assert(!PointOriginFor, isq::time>); -static_assert(!PointOriginFor, isq::length>); -static_assert(!PointOriginFor, isq::radius>); -static_assert(!PointOriginFor, isq::time>); -static_assert(!PointOriginFor, isq::length>); -static_assert(!PointOriginFor, isq::radius>); -static_assert(!PointOriginFor, isq::time>); -static_assert(!PointOriginFor, isq::length>); -static_assert(!PointOriginFor, isq::radius>); -static_assert(!PointOriginFor, isq::time>); -static_assert(!PointOriginFor); +static_assert(PointOriginFor); +static_assert(PointOriginFor); +static_assert(!PointOriginFor); +static_assert(PointOriginFor); +static_assert(PointOriginFor); +static_assert(!PointOriginFor); +static_assert(!PointOriginFor, (isq::length)>); +static_assert(!PointOriginFor, (isq::radius)>); +static_assert(!PointOriginFor, (isq::time)>); +static_assert(!PointOriginFor, (isq::length)>); +static_assert(!PointOriginFor, (isq::radius)>); +static_assert(!PointOriginFor, (isq::time)>); +static_assert(!PointOriginFor, (isq::length)>); +static_assert(!PointOriginFor, (isq::radius)>); +static_assert(!PointOriginFor, (isq::time)>); +static_assert(!PointOriginFor, (isq::length)>); +static_assert(!PointOriginFor, (isq::radius)>); +static_assert(!PointOriginFor, (isq::time)>); +static_assert(!PointOriginFor); #if MP_UNITS_HOSTED -static_assert(!PointOriginFor); -static_assert(!PointOriginFor, isq::length>); +static_assert(!PointOriginFor); +static_assert(!PointOriginFor, (isq::length)>); #endif -static_assert(!PointOriginFor); +static_assert(!PointOriginFor); // QuantityPointLike #if MP_UNITS_HOSTED static_assert(QuantityPointLike>); static_assert(!QuantityPointLike); #endif -static_assert(!QuantityPointLike>); -static_assert(!QuantityPointLike>); +static_assert(!QuantityPointLike>); +static_assert(!QuantityPointLike>); static_assert(!QuantityPointLike); } // namespace diff --git a/test/static/custom_rep_test_min_impl.cpp b/test/static/custom_rep_test_min_impl.cpp index 4fb2537b..8b328557 100644 --- a/test/static/custom_rep_test_min_impl.cpp +++ b/test/static/custom_rep_test_min_impl.cpp @@ -78,18 +78,18 @@ static_assert(Representation>); static_assert(Representation>); // construction from a value is not allowed -static_assert(!std::constructible_from>, min_impl>); -static_assert(!std::convertible_to, quantity>>); +static_assert(!std::constructible_from>, min_impl>); +static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); -static_assert(!std::constructible_from>, min_impl>); -static_assert(!std::convertible_to, quantity>>); +static_assert(!std::constructible_from>, min_impl>); +static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); // multiply syntax should work template concept creates_quantity = Unit && requires { T{} * U; }; -static_assert(creates_quantity, si::metre>); -static_assert(creates_quantity, si::metre>); +static_assert(creates_quantity, (si::metre)>); +static_assert(creates_quantity, (si::metre)>); // multiply syntax static_assert(creates_quantity, one>); @@ -99,46 +99,47 @@ static_assert(creates_quantity, percent>); // construction from a quantity // min_impl -> min_impl -static_assert(std::constructible_from>, quantity>>); -static_assert(std::convertible_to>, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); -static_assert(std::constructible_from>, quantity>>); -static_assert(std::convertible_to>, quantity>>); +static_assert( + std::constructible_from>, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); -static_assert(std::constructible_from>, quantity>>); -static_assert(std::convertible_to>, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); -static_assert(!std::constructible_from>, - quantity>>); // narrowing conversion -static_assert(!std::convertible_to>, quantity>>); +static_assert(!std::constructible_from>, + quantity<(si::metre), min_impl>>); // narrowing conversion +static_assert(!std::convertible_to>, quantity<(si::metre), min_impl>>); // T -> min_impl -static_assert(std::constructible_from>, quantity>); -static_assert(std::convertible_to, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), int>>); +static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); -static_assert(std::constructible_from>, quantity>); -static_assert(std::convertible_to, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), double>>); +static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); -static_assert(std::constructible_from>, quantity>); -static_assert(std::convertible_to, quantity>>); +static_assert(std::constructible_from>, quantity<(si::metre), int>>); +static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); -static_assert( - !std::constructible_from>, quantity>); // narrowing conversion -static_assert(!std::convertible_to, quantity>>); +static_assert(!std::constructible_from>, + quantity<(si::metre), double>>); // narrowing conversion +static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); // min_impl -> T -static_assert(std::constructible_from, quantity>>); -static_assert(std::convertible_to>, quantity>); +static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), int>>); -static_assert(std::constructible_from, quantity>>); -static_assert(std::convertible_to>, quantity>); +static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), double>>); -static_assert(std::constructible_from, quantity>>); -static_assert(std::convertible_to>, quantity>); +static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); +static_assert(std::convertible_to>, quantity<(si::metre), double>>); -static_assert( - !std::constructible_from, quantity>>); // narrowing conversion -static_assert(!std::convertible_to>, quantity>); +static_assert(!std::constructible_from, + quantity<(si::metre), min_impl>>); // narrowing conversion +static_assert(!std::convertible_to>, quantity<(si::metre), int>>); // arithmetic operators diff --git a/test/static/dimension_test.cpp b/test/static/dimension_test.cpp index 8064831e..f1d64590 100644 --- a/test/static/dimension_test.cpp +++ b/test/static/dimension_test.cpp @@ -33,7 +33,7 @@ namespace { using namespace mp_units; -using dimension_one_ = struct dimension_one; +using dimension_one_ = struct mp_units::dimension_one; // clang-format off inline constexpr struct length_ final : base_dimension<"L"> {} length; diff --git a/test/static/quantity_point_test.cpp b/test/static/quantity_point_test.cpp index f04e9c1a..50dfb67e 100644 --- a/test/static/quantity_point_test.cpp +++ b/test/static/quantity_point_test.cpp @@ -58,24 +58,24 @@ inline constexpr struct mean_sea_level final : absolute_point_origin { +inline constexpr struct same_mean_sea_level final : relative_point_origin { } same_mean_sea_level; -inline constexpr struct ground_level final : relative_point_origin { +inline constexpr struct ground_level final : relative_point_origin { } ground_level; inline constexpr auto my_ground_level = ground_level; -inline constexpr struct same_ground_level1 final : relative_point_origin { +inline constexpr struct same_ground_level1 final : relative_point_origin { } same_ground_level1; -inline constexpr struct same_ground_level2 final : relative_point_origin { +inline constexpr struct same_ground_level2 final : relative_point_origin { } same_ground_level2; -inline constexpr struct tower_peak final : relative_point_origin { +inline constexpr struct tower_peak final : relative_point_origin { } tower_peak; -inline constexpr struct other_ground_level final : relative_point_origin { +inline constexpr struct other_ground_level final : relative_point_origin { } other_ground_level; inline constexpr struct other_absolute_level final : absolute_point_origin { @@ -152,10 +152,10 @@ static_assert(zeroth_point_origin != zeroth_point_origin) == sizeof(double)); -static_assert(sizeof(quantity_point) == sizeof(double)); -static_assert(sizeof(quantity_point) == sizeof(short)); -static_assert(sizeof(quantity_point) == sizeof(short)); +static_assert(sizeof(quantity_point<(si::metre), mean_sea_level>) == sizeof(double)); +static_assert(sizeof(quantity_point<(isq::height[m]), mean_sea_level>) == sizeof(double)); +static_assert(sizeof(quantity_point<(si::metre), ground_level, short>) == sizeof(short)); +static_assert(sizeof(quantity_point<(isq::height[m]), ground_level, short>) == sizeof(short)); template typename QP> concept invalid_types = requires { @@ -188,15 +188,15 @@ static_assert(invalid_types); template typename QP> concept valid_types = requires { - typename QP; - typename QP; - typename QP; - typename QP; - typename QP; - typename QP; - typename QP, int>; - typename QP>, int>; - typename QP, int>; + typename QP<(si::metre), mean_sea_level, int>; + typename QP<(isq::height[m]), mean_sea_level, int>; + typename QP<(special_height[m]), mean_sea_level, int>; + typename QP<(si::metre), ground_level, int>; + typename QP<(isq::height[m]), ground_level, int>; + typename QP<(special_height[m]), ground_level, int>; + typename QP<(isq::height[m]), zeroth_point_origin<(isq::length)>, int>; + typename QP<(isq::height[m]), zeroth_point_origin>, int>; + typename QP<(si::metre), zeroth_point_origin<(isq::height)>, int>; }; static_assert(valid_types); @@ -217,14 +217,14 @@ static_assert(std::is_nothrow_destructible_v>); static_assert(std::is_standard_layout_v>); -static_assert(std::default_initializable>); -static_assert(std::move_constructible>); -static_assert(std::copy_constructible>); -static_assert(std::equality_comparable>); -static_assert(std::totally_ordered>); -static_assert(std::regular>); +static_assert(std::default_initializable>); +static_assert(std::move_constructible>); +static_assert(std::copy_constructible>); +static_assert(std::equality_comparable>); +static_assert(std::totally_ordered>); +static_assert(std::regular>); -static_assert(std::three_way_comparable>); +static_assert(std::three_way_comparable>); ////////////////// @@ -235,51 +235,53 @@ static_assert(quantity_point::reference == si::metre); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, zeroth_point_origin_>>); -static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>>); +static_assert(is_of_type::point_origin, zeroth_point_origin_>>); +static_assert( + is_of_type::absolute_point_origin, zeroth_point_origin_>>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, zeroth_point_origin_>); -static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>); +static_assert(is_of_type::point_origin, zeroth_point_origin_>); +static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>); static_assert(quantity_point::reference == si::metre); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct mean_sea_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct mean_sea_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct mean_sea_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct mean_sea_level>); +static_assert( + is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct ground_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct ground_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct tower_peak>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct tower_peak>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == si::kelvin); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, struct si::absolute_zero>); +static_assert(is_of_type::point_origin, struct si::absolute_zero>); static_assert( - is_of_type::absolute_point_origin, struct si::absolute_zero>); + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == isq::thermodynamic_temperature[si::kelvin]); @@ -288,10 +290,11 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, - struct si::absolute_zero>); static_assert( - is_of_type::absolute_point_origin, + is_of_type::point_origin, + struct si::absolute_zero>); +static_assert( + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == @@ -301,19 +304,20 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, - struct si::absolute_zero>); -static_assert(is_of_type::absolute_point_origin, +static_assert(is_of_type::point_origin, struct si::absolute_zero>); +static_assert( + is_of_type::absolute_point_origin, + struct si::absolute_zero>); static_assert(quantity_point::reference == si::degree_Celsius); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::degree_Celsius); -static_assert(is_of_type::point_origin, struct si::ice_point>); +static_assert(is_of_type::point_origin, struct si::ice_point>); static_assert( - is_of_type::absolute_point_origin, struct si::absolute_zero>); + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == isq::Celsius_temperature[si::degree_Celsius]); @@ -322,10 +326,10 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::degree_Celsius); -static_assert(is_of_type::point_origin, +static_assert(is_of_type::point_origin, struct si::ice_point>); static_assert( - is_of_type::absolute_point_origin, + is_of_type::absolute_point_origin, struct si::absolute_zero>); @@ -333,18 +337,18 @@ static_assert( // member types ////////////////// -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, int>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, int>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, int>); +static_assert(is_same_v::rep, int>); static_assert( - is_same_v::quantity_type, quantity>); + is_same_v::quantity_type, quantity>); //////////////////////////// @@ -371,11 +375,11 @@ static_assert( ////////////////////////////// // there is no construction from a value -static_assert(!std::constructible_from, double>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, double>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, int>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, int>); +static_assert(!std::convertible_to>); static_assert(!std::constructible_from, double>); static_assert(!std::convertible_to>); @@ -396,135 +400,135 @@ static_assert(!std::convertible_to, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(si::metre)>>); +static_assert(!std::convertible_to, quantity_point<(si::metre)>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(si::metre)>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(si::metre)>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::speed[m / s])>>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::speed[m / s])>>); +static_assert(!std::convertible_to, quantity_point<(isq::length[m] / isq::time[s])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::length[m] / isq::time[s])>>); +static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); static_assert(std::constructible_from, quantity>); static_assert(!std::convertible_to, quantity_point>); // different dimensions -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(si::second)>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // convertible but different quantity_specs -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::length[m])>>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity<(special_height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::width[m])>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::width[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::length[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); #if MP_UNITS_HOSTED // quantity-like -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); #endif // ---------------------- // explicit point origins // ---------------------- -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(si::metre)>>); +static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(si::metre)>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); static_assert(!std::constructible_from, quantity>); static_assert(!std::convertible_to, quantity_point>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::width[m]), zeroth_length>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::width[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), zeroth_length>>); // different dimensions -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(si::second)>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::length[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); // not-compatible origin -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity<(isq::length[m])>>); +static_assert(!std::convertible_to, quantity_point<((si::metre)), mean_sea_level>>); #if MP_UNITS_HOSTED // quantity-like -static_assert(!std::constructible_from>, +static_assert(!std::constructible_from>, std::chrono::seconds>); static_assert(!std::convertible_to>>); + quantity_point<(si::second), chrono_point_origin>>); -static_assert(!std::constructible_from>, +static_assert(!std::constructible_from>, std::chrono::seconds>); static_assert(!std::convertible_to>>); + quantity_point<(isq::time[s]), chrono_point_origin>>); static_assert( - !std::constructible_from>, + !std::constructible_from>, std::chrono::seconds>); static_assert( !std::convertible_to>>); + quantity_point<(isq::period_duration[s]), chrono_point_origin>>); #endif @@ -533,140 +537,146 @@ static_assert( /////////////////////////////////////// // implicit origin -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point<(si::metre)>>); +static_assert(std::convertible_to, quantity_point<(si::metre)>>); +static_assert(std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(std::convertible_to, quantity_point<(isq::height[m])>>); -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(std::convertible_to, quantity_point<(si::metre)>>); +static_assert(std::constructible_from, quantity_point<(si::metre)>>); +static_assert(std::convertible_to, quantity_point<(isq::height[m])>>); static_assert( - std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); + std::constructible_from, quantity_point<(isq::speed[m / s])>>); +static_assert( + std::convertible_to, quantity_point<(isq::length[m]) / isq::time[s]>>); -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point<(isq::speed[m / s])>>); +static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point<(isq::length[m]) / isq::time[s]>>); +static_assert(std::convertible_to, quantity_point>); // convertible but different quantity_specs -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::length[m])>>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::width[m])>>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(isq::width[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(isq::length[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point>); // mixed origins -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(si::metre)>>); +static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); +static_assert( + !std::constructible_from, quantity_point<(isq::height[m])>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); +static_assert(!std::convertible_to, quantity_point<(si::metre)>>); +static_assert( + !std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); // same explicit origins static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert(std::constructible_from, - quantity_point>); -static_assert( - std::convertible_to, quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::constructible_from, - quantity_point>); -static_assert( - std::convertible_to, quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[km]), mean_sea_level>>); -static_assert(std::constructible_from, - quantity_point>); -static_assert( - std::convertible_to, quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[km]), mean_sea_level>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); -static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); -static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::constructible_from, +static_assert(std::constructible_from, quantity_point>); static_assert(std::convertible_to, - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); + std::constructible_from, quantity_point<(si::metre), ground_level>>); +static_assert( + std::convertible_to, quantity_point<(si::metre), ground_level>>); + +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), ground_level>>); +static_assert( + std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); + +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[km]), mean_sea_level>>); + +static_assert(std::constructible_from, + quantity_point<(isq::height[km]), ground_level>>); +static_assert( + std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(isq::height[m]), ground_level>>); static_assert( - std::convertible_to, quantity_point>); - -static_assert(std::constructible_from, - quantity_point>); -static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(si::metre), ground_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(si::metre), ground_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); -static_assert( - std::constructible_from, quantity_point>); -static_assert( - std::convertible_to, quantity_point>); - -static_assert( - std::constructible_from, quantity_point>); -static_assert( - std::convertible_to, quantity_point>); - -static_assert(std::constructible_from, +static_assert(std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); static_assert( - std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); + std::constructible_from, quantity_point<(si::metre), ground_level>>); +static_assert( + std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); -static_assert(std::convertible_to, quantity_point>); + std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); +static_assert( + std::convertible_to, quantity_point<(si::metre), ground_level>>); static_assert( - std::constructible_from, quantity_point>); + std::constructible_from, quantity_point<(si::metre), other_ground_level>>); static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(si::metre), ground_level>>); static_assert( std::constructible_from, quantity_point>); @@ -682,121 +692,121 @@ static_assert( static_assert( std::convertible_to, quantity_point>); -static_assert(std::constructible_from, - quantity_point>); -static_assert( - std::convertible_to, quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), zeroth_length>>); +static_assert(std::convertible_to, + quantity_point<(isq::length[m]), zeroth_length>>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, - quantity_point>); -static_assert( - !std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), zeroth_length>>); +static_assert(!std::convertible_to, + quantity_point<(isq::width[m]), zeroth_length>>); -static_assert(!std::constructible_from, - quantity_point>); -static_assert( - !std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(isq::width[m]), zeroth_length>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), zeroth_length>>); // different dimensions -static_assert( - !std::constructible_from, quantity_point>); -static_assert( - !std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(si::kelvin), (si::ice_point)>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); // non-convertible quantity_specs static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::convertible_to, quantity_point>); // implicit conversion from another quantity point only if non-truncating // int -> double OK -static_assert(std::constructible_from, - quantity_point>); -static_assert(std::convertible_to, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level, int>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); // truncating double -> int not allowed -static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, - quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level, int>>); // kilometre -> metre OK -static_assert(std::constructible_from, - quantity_point>); -static_assert(std::convertible_to, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[km]), mean_sea_level, int>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level, int>>); // truncating metre -> kilometre not allowed -static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, - quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level, int>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[km]), mean_sea_level, int>>); // converting to double always OK -static_assert(std::constructible_from, - quantity_point>); -static_assert(std::convertible_to, - quantity_point>); -static_assert(std::constructible_from, - quantity_point>); -static_assert(std::convertible_to, - quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[km]), mean_sea_level, int>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level, int>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[km]), mean_sea_level>>); // same but not a default origin -static_assert(std::constructible_from, - quantity_point>); -static_assert( - std::convertible_to, quantity_point>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); -static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::constructible_from, quantity_point>); -static_assert( - std::convertible_to, quantity_point>); + std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::constructible_from, +static_assert(std::constructible_from, quantity_point>); static_assert(std::convertible_to, - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level>>); static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::convertible_to, quantity_point>); // different origins -static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, - quantity_point>); -static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, - quantity_point>); -static_assert(!std::constructible_from, - quantity_point>); -static_assert(!std::convertible_to, - quantity_point>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), other_absolute_level>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), other_absolute_level>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), ground_level>>); +static_assert(!std::constructible_from, + quantity_point<(isq::height[m]), ground_level>>); +static_assert(!std::convertible_to, + quantity_point<(isq::height[m]), other_absolute_level>>); #if MP_UNITS_HOSTED // quantity-point-like static_assert( - std::constructible_from>, sys_seconds>); + std::constructible_from>, sys_seconds>); static_assert( - std::convertible_to>>); + std::convertible_to>>); // incompatible origin +static_assert(!std::constructible_from>, + sys_seconds>); static_assert( - !std::constructible_from>, sys_seconds>); -static_assert( - !std::convertible_to>>); + !std::convertible_to>>); #endif @@ -825,17 +835,19 @@ static_assert((mean_sea_level + 42 * m).quantity_from(mean_sea_level) == 42 * m) static_assert((ground_level + 42 * m).quantity_from(ground_level) == 42 * m); static_assert((tower_peak + 42 * m).quantity_from(tower_peak) == 42 * m); -static_assert(quantity_point(ground_level + 42 * m).quantity_from(mean_sea_level) == +static_assert(quantity_point<(isq::height[m]), mean_sea_level>(ground_level + 42 * m).quantity_from(mean_sea_level) == 84 * m); -static_assert(quantity_point(tower_peak + 42 * m).quantity_from(mean_sea_level) == +static_assert(quantity_point<(isq::height[m]), mean_sea_level>(tower_peak + 42 * m).quantity_from(mean_sea_level) == 126 * m); -static_assert(quantity_point(mean_sea_level + 84 * m).quantity_from(ground_level) == +static_assert(quantity_point<(isq::height[m]), ground_level>(mean_sea_level + 84 * m).quantity_from(ground_level) == 42 * m); -static_assert(quantity_point(tower_peak + 42 * m).quantity_from(ground_level) == 84 * m); +static_assert(quantity_point<(isq::height[m]), ground_level>(tower_peak + 42 * m).quantity_from(ground_level) == + 84 * m); -static_assert(quantity_point(mean_sea_level + 42 * m).quantity_from(tower_peak) == -42 * m); -static_assert(quantity_point(ground_level + 84 * m).quantity_from(tower_peak) == 42 * m); +static_assert(quantity_point<(isq::height[m]), tower_peak>(mean_sea_level + 42 * m).quantity_from(tower_peak) == + -42 * m); +static_assert(quantity_point<(isq::height[m]), tower_peak>(ground_level + 84 * m).quantity_from(tower_peak) == 42 * m); static_assert((mean_sea_level + 42 * m).point_for(mean_sea_level).quantity_from(mean_sea_level) == 42 * m); static_assert((ground_level + 42 * m).point_for(mean_sea_level).quantity_from(mean_sea_level) == 84 * m); @@ -850,7 +862,7 @@ static_assert((mean_sea_level + 42 * m).point_for(tower_peak).quantity_from(towe static_assert((ground_level + 84 * m).point_for(tower_peak).quantity_from(tower_peak) == 42 * m); static_assert(is_of_type<(ground_level + isq::height(short{42} * m)).point_for(mean_sea_level), - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); /////////////////////////////////// @@ -877,8 +889,8 @@ static_assert(is_of_type<(mean_sea_level + 2500. * m).force_in(km), quantit template typename QP> concept invalid_unit_conversion = requires { - requires !requires { QP(2000 * m).in(km); }; // truncating conversion - requires !requires { QP(2 * m).in(s); }; // invalid unit + requires !requires { QP<(isq::height[m]), mean_sea_level, int>(2000 * m).in(km); }; // truncating conversion + requires !requires { QP<(isq::height[m]), mean_sea_level, int>(2 * m).in(s); }; // invalid unit }; static_assert(invalid_unit_conversion); @@ -926,13 +938,12 @@ static_assert(quantity_point{sys_seconds{24h}}.quantity_spec == kind_of typename QP> concept invalid_compound_assignments = requires() { // truncating not allowed - requires !requires(QP l) { l += 2.5 * m; }; - requires !requires(QP l) { l -= 2.5 * m; }; - requires !requires(QP l) { l += 2 * isq::height[m]; }; - requires !requires(QP l) { l -= 2 * isq::height[m]; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += 2.5 * m; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= 2.5 * m; }; + requires !requires(QP l) { l += 2 * (isq::height[m]); }; + requires !requires(QP l) { l -= 2 * (isq::height[m]); }; // only quantities can be added or subtracted - requires !requires(QP l) { l += 2; }; - requires !requires(QP l) { l -= 2; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += 2; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= 2; }; // no unit constants - requires !requires(QP l) { l += m; }; - requires !requires(QP l) { l -= m; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += m; }; + requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= m; }; }; static_assert(invalid_compound_assignments); @@ -1132,12 +1143,12 @@ concept invalid_binary_operations = requires { requires !requires { Origin - Origin; }; // unit constants - requires !requires { QP(1) + m; }; - requires !requires { QP(1) - m; }; + requires !requires { QP<(si::metre), mean_sea_level, int>(1) + m; }; + requires !requires { QP<(si::metre), mean_sea_level, int>(1) - m; }; requires !requires { Origin + m; }; requires !requires { Origin - m; }; - requires !requires { m + QP(1); }; - requires !requires { m - QP(1); }; + requires !requires { m + QP<(si::metre), mean_sea_level, int>(1); }; + requires !requires { m - QP<(si::metre), mean_sea_level, int>(1); }; requires !requires { m + Origin; }; requires !requires { m - Origin; }; }; @@ -1174,36 +1185,36 @@ static_assert(is_of_type<1 * m + (mean_sea_level + 1 * km), quantity_point>); static_assert( - is_of_type<1 * m + (mean_sea_level + isq::height(1 * m)), quantity_point>); + is_of_type<1 * m + (mean_sea_level + isq::height(1 * m)), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<1 * m + (mean_sea_level + isq::height(1 * km)), quantity_point>); + is_of_type<1 * m + (mean_sea_level + isq::height(1 * km)), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<1 * km + (mean_sea_level + isq::height(1 * m)), quantity_point>); + is_of_type<1 * km + (mean_sea_level + isq::height(1 * m)), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type>); + is_of_type>); static_assert( - is_of_type>); + is_of_type>); static_assert( - is_of_type>); + is_of_type>); static_assert(is_of_type>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type>); static_assert(is_of_type, mean_sea_level, int>>); -static_assert(is_of_type>); +static_assert(is_of_type>); static_assert( is_of_type>); static_assert(is_of_type], mean_sea_level, int>>); static_assert(is_of_type<1 * m + mean_sea_level, quantity_point>); static_assert(is_of_type<1 * km + mean_sea_level, quantity_point, mean_sea_level, int>>); -static_assert(is_of_type>); +static_assert(is_of_type>); static_assert( is_of_type>); static_assert(is_of_type>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * m), quantity_point>); + is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * m), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * km), quantity_point>); + is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * km), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<(mean_sea_level + 1 * km) - isq::height(1 * m), quantity_point>); + is_of_type<(mean_sea_level + 1 * km) - isq::height(1 * m), quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * m, quantity_point>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * m, quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * km, quantity_point>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * km, quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * km)) - 1 * m, quantity_point>); + is_of_type<(mean_sea_level + isq::height(1 * km)) - 1 * m, quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - isq::height(1 * m), - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - isq::height(1 * km), - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * km)) - isq::height(1 * m), - quantity_point>); + quantity_point<(isq::height[m]), mean_sea_level, int>>); static_assert(is_of_type>); static_assert(is_of_type, mean_sea_level, int>>); @@ -1254,39 +1265,39 @@ static_assert(is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + 1 * m), q static_assert(is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + 1 * km), quantity>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * m)), quantity>); + is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * m)), quantity<(isq::height[m]), int>>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * km)), quantity>); + is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * km)), quantity<(isq::height[m]), int>>); static_assert( - is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + isq::height(1 * m)), quantity>); + is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + isq::height(1 * m)), quantity<(isq::height[m]), int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * m), quantity>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * km), quantity>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * km), quantity<(isq::height[m]), int>>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + 1 * m), quantity>); + is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + isq::height(1 * m)), - quantity>); + quantity<(isq::height[m]), int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + isq::height(1 * km)), - quantity>); + quantity<(isq::height[m]), int>>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + isq::height(1 * m)), - quantity>); + quantity<(isq::height[m]), int>>); static_assert(is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + 1 * m), quantity>); static_assert(is_of_type<(ground_level + 1 * m) - (ground_level + 1 * m), quantity>); static_assert(is_of_type<(tower_peak + 1 * m) - (tower_peak + 1 * m), quantity>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - (ground_level + 1 * m), quantity>); -static_assert(is_of_type<(ground_level + 1 * m) - (mean_sea_level + 1 * m), quantity>); -static_assert(is_of_type<(tower_peak + 1 * m) - (ground_level + 1 * m), quantity>); -static_assert(is_of_type<(ground_level + 1 * m) - (tower_peak + 1 * m), quantity>); -static_assert(is_of_type<(tower_peak + 1 * m) - (mean_sea_level + 1 * m), quantity>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - (tower_peak + 1 * m), quantity>); -static_assert(is_of_type<(other_ground_level + 1 * m) - (ground_level + 1 * m), quantity>); -static_assert(is_of_type<(ground_level + 1 * m) - (other_ground_level + 1 * m), quantity>); -static_assert(is_of_type<(other_ground_level + 1 * m) - (tower_peak + 1 * m), quantity>); -static_assert(is_of_type<(tower_peak + 1 * m) - (other_ground_level + 1 * m), quantity>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(ground_level + 1 * m) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(tower_peak + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(ground_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(tower_peak + 1 * m) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(other_ground_level + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(ground_level + 1 * m) - (other_ground_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(other_ground_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(tower_peak + 1 * m) - (other_ground_level + 1 * m), quantity<(isq::height[m]), int>>); static_assert(is_of_type>); static_assert(is_of_type, int>>); @@ -1298,32 +1309,32 @@ static_assert(is_of_type>); static_assert(is_of_type<(ground_level + 1 * km) - ground_level, quantity, int>>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type<(ground_level + 1 * m) - mean_sea_level, quantity>); -static_assert(is_of_type<(ground_level + 1 * km) - mean_sea_level, quantity>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type<(ground_level + 1 * m) - mean_sea_level, quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(ground_level + 1 * km) - mean_sea_level, quantity<(isq::height[m]), int>>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - ground_level, quantity>); -static_assert(is_of_type<(mean_sea_level + 1 * km) - ground_level, quantity>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - ground_level, quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(mean_sea_level + 1 * km) - ground_level, quantity<(isq::height[m]), int>>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); -static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + ground_level), quantity>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + mean_sea_level), quantity>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + ground_level), quantity>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + tower_peak), quantity>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + mean_sea_level), quantity>); -static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + tower_peak), quantity>); -static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + ground_level), quantity>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + other_ground_level), quantity>); -static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + tower_peak), quantity>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + other_ground_level), quantity>); +static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + mean_sea_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + mean_sea_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + other_ground_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + other_ground_level), quantity<(isq::height[m]), int>>); // check for integral types promotion @@ -1643,8 +1654,8 @@ static_assert(is_of_type<(zero_Hz + 5 * isq::frequency[Hz]) - (zero_Hz + 10 / (2 static_assert((quantity_point{10 / (2 * isq::period_duration[s])} + 5 * isq::frequency[Hz]).quantity_from_zero() == 10 * isq::frequency[Hz]); -static_assert((10 / (2 * isq::period_duration[s]) + quantity_point{zero_Hz + 5 * isq::frequency[Hz]}) - .quantity_from_zero() == 10 * isq::frequency[Hz]); +static_assert((10 / (2 * isq::period_duration[s]) + (zero_Hz + 5 * isq::frequency[Hz])).quantity_from_zero() == + 10 * isq::frequency[Hz]); static_assert((quantity_point{5 * isq::frequency[Hz]} + 10 / (2 * isq::period_duration[s])).quantity_from_zero() == 10 * isq::frequency[Hz]); static_assert((5 * isq::frequency[Hz] + quantity_point{10 / (2 * isq::period_duration[s])}).quantity_from_zero() == @@ -1718,7 +1729,7 @@ static_assert(value_cast(quantity_point{2 * km}).quantity_from_zero().numeric static_assert(value_cast(quantity_point{2000 * m}).quantity_from_zero().numerical_value_in(km) == 2); static_assert(value_cast(quantity_point{1.23 * m}).quantity_from_zero().numerical_value_in(m) == 1); static_assert( - value_cast(quantity_point{2000.0 * m / (3600.0 * s)}).quantity_from_zero().numerical_value_in(km / h) == 2); + value_cast<(km / h)>(quantity_point{2000.0 * m / (3600.0 * s)}).quantity_from_zero().numerical_value_in(km / h) == 2); // lvalue references in value_cast namespace lvalue_tests { constexpr quantity_point lvalue_qp{2 * km}; diff --git a/test/static/quantity_spec_test.cpp b/test/static/quantity_spec_test.cpp index ee4e86a8..ed4cb359 100644 --- a/test/static/quantity_spec_test.cpp +++ b/test/static/quantity_spec_test.cpp @@ -33,8 +33,8 @@ namespace { using namespace mp_units; -using dimensionless_ = struct dimensionless; -using dim_one_ = struct dimension_one; +using dimensionless_ = struct mp_units::dimensionless; +using dim_one_ = struct mp_units::dimension_one; // clang-format off inline constexpr struct dim_length_ final : base_dimension<"L"> {} dim_length; diff --git a/test/static/quantity_test.cpp b/test/static/quantity_test.cpp index 89f169bb..44ee65ad 100644 --- a/test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -84,14 +84,14 @@ static_assert(std::is_nothrow_destructible_v>); static_assert(std::is_trivially_copyable_v>); static_assert(std::is_standard_layout_v>); -static_assert(std::default_initializable>); -static_assert(std::move_constructible>); -static_assert(std::copy_constructible>); -static_assert(std::equality_comparable>); -static_assert(std::totally_ordered>); -static_assert(std::regular>); +static_assert(std::default_initializable>); +static_assert(std::move_constructible>); +static_assert(std::copy_constructible>); +static_assert(std::equality_comparable>); +static_assert(std::totally_ordered>); +static_assert(std::regular>); -static_assert(std::three_way_comparable>); +static_assert(std::three_way_comparable>); ////////////////// @@ -112,8 +112,8 @@ static_assert(quantity::unit == si::metre); // member types ///////////////// -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::rep, int>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::rep, int>); [[maybe_unused]] volatile std::int16_t vint = 123; static_assert(is_same_v); @@ -139,11 +139,11 @@ static_assert(quantity::max().numerical_value_in(m) == s ///////////////////////////////////////////////// // construction from a value is private -static_assert(!std::constructible_from, double>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, double>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, int>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, int>); +static_assert(!std::convertible_to>); static_assert(std::constructible_from, double>); static_assert(std::convertible_to>); @@ -163,45 +163,46 @@ static_assert(std::convertible_to>); /////////////////////////////////////// // conversion only between convertible quantities -static_assert(std::constructible_from, quantity>); -static_assert(std::convertible_to, quantity>); -static_assert(std::constructible_from, quantity>); -static_assert(std::convertible_to, quantity>); -static_assert(std::constructible_from, quantity>); -static_assert(std::convertible_to, quantity>); +static_assert(std::constructible_from, quantity<(isq::length[m])>>); +static_assert(std::convertible_to, quantity<(isq::length[m])>>); +static_assert(std::constructible_from, quantity<(isq::distance[m])>>); +static_assert(std::convertible_to, quantity<(isq::length[m])>>); +static_assert(std::constructible_from, quantity<(isq::length[km])>>); +static_assert(std::convertible_to, quantity<(isq::length[m])>>); // conversion between different quantities not allowed -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity>); +static_assert(!std::constructible_from, quantity<(isq::time[s])>>); +static_assert(!std::convertible_to, quantity<(isq::length[m])>>); +static_assert(!std::constructible_from, quantity<(isq::speed[m / s])>>); +static_assert(!std::convertible_to, quantity<(isq::length[m])>>); // implicit conversion from another quantity only if non-truncating -static_assert(std::constructible_from, quantity>); // int -> double OK -static_assert(std::convertible_to, quantity>); // int -> double OK - -static_assert(!std::constructible_from, - quantity>); // truncating double -> int not allowed -static_assert(!std::convertible_to, - quantity>); // truncating double -> int not allowed - -static_assert(std::constructible_from, - quantity>); // kilometre -> metre OK -static_assert(std::convertible_to, - quantity>); // kilometre -> metre OK - -static_assert(!std::constructible_from, - quantity>); // truncating metre -> - // kilometre not allowed static_assert( - !std::convertible_to, - quantity>); // truncating metre -> kilometre not allowed + std::constructible_from, quantity<(isq::length[m]), int>>); // int -> double OK +static_assert(std::convertible_to, quantity<(isq::length[m])>>); // int -> double OK + +static_assert(!std::constructible_from, + quantity<(isq::length[m])>>); // truncating double -> int not allowed +static_assert(!std::convertible_to, + quantity<(isq::length[m]), int>>); // truncating double -> int not allowed + +static_assert(std::constructible_from, + quantity<(isq::length[km]), int>>); // kilometre -> metre OK +static_assert(std::convertible_to, + quantity<(isq::length[m]), int>>); // kilometre -> metre OK + +static_assert(!std::constructible_from, + quantity<(isq::length[m]), int>>); // truncating metre -> + // kilometre not allowed +static_assert( + !std::convertible_to, + quantity<(isq::length[km]), int>>); // truncating metre -> kilometre not allowed // converting to double always OK -static_assert(std::constructible_from, quantity>); -static_assert(std::convertible_to, quantity>); -static_assert(std::constructible_from, quantity>); -static_assert(std::convertible_to, quantity>); +static_assert(std::constructible_from, quantity<(isq::length[km]), int>>); +static_assert(std::convertible_to, quantity<(isq::length[m])>>); +static_assert(std::constructible_from, quantity<(isq::length[m]), int>>); +static_assert(std::convertible_to, quantity<(isq::length[km])>>); /////////////////////// // obtaining a number @@ -219,16 +220,16 @@ static_assert(quantity(1500 * m).numerical_value_in(km) == 1.5) static_assert(!std::convertible_to, double>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, double>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, double>); +static_assert(std::constructible_from>); static_assert(!std::convertible_to, int>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, int>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, int>); +static_assert(std::constructible_from>); static_assert(!std::convertible_to, double>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, double>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, double>); +static_assert(std::constructible_from>); /////////////////////////////////// @@ -318,9 +319,9 @@ struct derived_quantity : quantity { R::operator=(t); return *this; } - constexpr derived_quantity& operator=(R&& t) + constexpr derived_quantity& operator=(R&& other) { - R::operator=(std::move(t)); + R::operator=(std::move(other)); return *this; } // NOLINTBEGIN(google-explicit-constructor, hicpp-explicit-conversions) @@ -331,9 +332,9 @@ struct derived_quantity : quantity { // NOLINTEND(google-explicit-constructor, hicpp-explicit-conversions) }; -static_assert(Quantity, "NTTP type description">>); +static_assert(Quantity, "NTTP type description">>); -constexpr QuantityOf auto get_length_derived_quantity() noexcept +constexpr QuantityOf<(isq::length)> auto get_length_derived_quantity() noexcept { derived_quantity, "NTTP type description"> dist{}; dist += 1 * m; @@ -362,7 +363,8 @@ static_assert(quantity{123}.quantity_spec == kind_of); #if MP_UNITS_HOSTED using namespace std::chrono_literals; static_assert(std::is_same_v); -static_assert(std::is_same_v); +// return type for "s" is not specified. is double for msvc +// static_assert(std::is_same_v); static_assert(quantity{24h}.unit == si::hour); static_assert(quantity{24h}.quantity_spec == kind_of); #endif @@ -461,10 +463,10 @@ static_assert((std::uint8_t{255}* m %= 257 * m).numerical_value_in(m) != [] { #if !(defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 18 && defined MP_UNITS_MODULES) // next two lines trigger conversions warnings // (warning disabled in CMake for this file) -static_assert((22 * m *= 33.33).numerical_value_in(m) == 733); -static_assert((22 * m /= 3.33).numerical_value_in(m) == 6); -static_assert((22 * m *= 33.33 * one).numerical_value_in(m) == 733); -static_assert((22 * m /= 3.33 * one).numerical_value_in(m) == 6); +static_assert(((22 * m) *= 33.33).numerical_value_in(m) == 733); +static_assert(((22 * m) /= 3.33).numerical_value_in(m) == 6); +static_assert(((22 * m) *= 33.33 * one).numerical_value_in(m) == 733); +static_assert(((22 * m) /= 3.33 * one).numerical_value_in(m) == 6); #endif template typename Q> @@ -850,27 +852,30 @@ static_assert(2 * one / (1 * m) == 2 / (1 * m)); // equality operators /////////////////////// -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity>); -static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity<(si::metre)>>); +static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity<(si::metre)>>); +static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); static_assert( - std::equality_comparable_with, quantity], int>>); + std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity<(si::metre)>>); +static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); +static_assert( + std::equality_comparable_with, quantity<(si::kilo<(si::metre)>), int>>); +static_assert(std::equality_comparable_with, quantity<(isq::height[(si::metre)])>>); +static_assert( + std::equality_comparable_with, quantity<(isq::height[(si::metre)]), int>>); +static_assert(std::equality_comparable_with, + quantity<(isq::height[(si::kilo<(si::metre)>)]), int>>); template concept no_crossdimensional_equality = requires { requires !requires { 1 * s == 1 * M; }; requires !requires { 1 * s != 1 * M; }; }; -static_assert(no_crossdimensional_equality); +static_assert(no_crossdimensional_equality<(si::metre)>); // same type static_assert(123 * m == 123 * m); @@ -923,7 +928,7 @@ concept no_crossdimensional_ordering = requires { requires !requires { 1 * s <= 1 * M; }; requires !requires { 1 * s >= 1 * M; }; }; -static_assert(no_crossdimensional_ordering); +static_assert(no_crossdimensional_ordering<(si::metre)>); // same type static_assert(123 * m < 321 * m); @@ -1037,34 +1042,35 @@ static_assert(is_of_type(lvalue_q), quantity, isq::length>); -static_assert(QuantityOf, isq::length>); -static_assert(QuantityOf, isq::length>); -static_assert(!QuantityOf, isq::width>); -static_assert(QuantityOf, isq::width>); -static_assert(QuantityOf, isq::position_vector>); -static_assert(QuantityOf[m]>, isq::width>); -static_assert(QuantityOf[m]>, isq::position_vector>); -static_assert(!QuantityOf, isq::altitude>); +static_assert(QuantityOf, (isq::length)>); +static_assert(QuantityOf, (isq::length)>); +static_assert(QuantityOf, (isq::length)>); +static_assert(!QuantityOf, (isq::width)>); +static_assert(QuantityOf, (isq::width)>); +static_assert(QuantityOf, (isq::position_vector)>); +static_assert(QuantityOf[m]>, (isq::width)>); +static_assert(QuantityOf[m]>, (isq::position_vector)>); +static_assert(!QuantityOf, isq::altitude>); -static_assert(QuantityOf, isq::speed>); -static_assert(QuantityOf, isq::length / isq::time>); +static_assert(QuantityOf, (isq::speed)>); +static_assert(QuantityOf, (isq::length) / (isq::time)>); static_assert(QuantityOf, isq::length / isq::time>); -static_assert(QuantityOf[m / s]>, isq::length / isq::time>); -static_assert(!QuantityOf, isq::distance / isq::duration>); -static_assert(!QuantityOf, isq::width / isq::duration>); +static_assert(QuantityOf[m / s]>, (isq::length) / (isq::time)>); +static_assert(!QuantityOf, (isq::distance) / (isq::duration)>); +static_assert(!QuantityOf, (isq::width) / (isq::duration)>); static_assert(QuantityOf, isq::width / isq::duration>); -static_assert(QuantityOf[m / s]>, isq::width / isq::duration>); -static_assert(!QuantityOf, isq::position_vector / isq::duration>); +static_assert(QuantityOf[m / s]>, (isq::width) / (isq::duration)>); +static_assert(!QuantityOf, (isq::position_vector) / (isq::duration)>); static_assert(QuantityOf, isq::position_vector / isq::duration>); -static_assert(QuantityOf[m / s]>, isq::position_vector / isq::duration>); -static_assert(QuantityOf, isq::position_vector / isq::duration>); +static_assert(QuantityOf[m / s]>, isq::position_vector / isq::duration>); +static_assert(QuantityOf, isq::position_vector / isq::duration>); -static_assert(QuantityOf); // kind of -static_assert(QuantityOf[m]), isq::height>); // kind of -static_assert(!QuantityOf); // different kinds -static_assert(!QuantityOf); // different kinds -static_assert(QuantityOf); -static_assert(QuantityOf); // derived unnamed quantity +static_assert(QuantityOf); // kind of +static_assert(QuantityOf[m]), (isq::height)>); // kind of +static_assert(!QuantityOf); // different kinds +static_assert(!QuantityOf); // different kinds +static_assert(QuantityOf); +static_assert( + QuantityOf); // derived unnamed quantity } // namespace diff --git a/test/static/reference_test.cpp b/test/static/reference_test.cpp index 65abe0bb..46026702 100644 --- a/test/static/reference_test.cpp +++ b/test/static/reference_test.cpp @@ -34,8 +34,8 @@ namespace { using namespace mp_units; -using dimensionless_ = struct dimensionless; -using one_ = struct one; +using dimensionless_ = struct mp_units::dimensionless; +using one_ = struct mp_units::one; // base dimensions // clang-format off @@ -238,7 +238,7 @@ template concept invalid_nu_unit = !requires { dim[unit]; }; static_assert(invalid_nu_unit); -static_assert(invalid_nu_unit); +static_assert(invalid_nu_unit<(nu::time), second>); static_assert(invalid_nu_unit); static_assert(invalid_nu_unit); static_assert(invalid_nu_unit); diff --git a/test/static/si_test.cpp b/test/static/si_test.cpp index 4f306fd2..d52a8edc 100644 --- a/test/static/si_test.cpp +++ b/test/static/si_test.cpp @@ -65,7 +65,7 @@ concept can_not_be_prefixed = Unit && !requires { typename prefix< static_assert(can_not_be_prefixed); static_assert(can_not_be_prefixed); -static_assert(can_not_be_prefixed>); +static_assert(can_not_be_prefixed)>); static_assert(can_not_be_prefixed); static_assert(can_not_be_prefixed * si::degree>); diff --git a/test/static/unit_test.cpp b/test/static/unit_test.cpp index ba7ecb4c..c16ea66a 100644 --- a/test/static/unit_test.cpp +++ b/test/static/unit_test.cpp @@ -35,8 +35,8 @@ namespace { using namespace mp_units; using namespace mp_units::detail; -using one_ = struct one; -using percent_ = struct percent; +using one_ = struct mp_units::one; +using percent_ = struct mp_units::percent; // base dimensions // clang-format off From 9ce76ede3a1b148f6502dc5d638e5bf7d86002cd Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:25:09 +0200 Subject: [PATCH 35/44] [msvc][fix] remvoe MP_UNITS_IS_CONST_EXPR_WORKAROUND in constexpr branches --- .../include/mp-units/framework/quantity_spec.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 934aa9b5..fee95bb5 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -669,10 +669,9 @@ template template [[nodiscard]] consteval bool ingredients_dimension_less(D1 lhs, D2 rhs) { - if constexpr (MP_UNITS_IS_CONST_EXPR_WORKAROUND(lhs) == MP_UNITS_IS_CONST_EXPR_WORKAROUND(rhs) || - MP_UNITS_IS_CONST_EXPR_WORKAROUND(lhs) == dimension_one) + if constexpr (D1{} == D2{} || D1{} == dimension_one) return false; - else if constexpr (MP_UNITS_IS_CONST_EXPR_WORKAROUND(rhs) == dimension_one) + else if constexpr (D2{} == dimension_one) return true; else return detail::type_name() < detail::type_name(); @@ -1341,12 +1340,10 @@ template using enum specs_convertible_result; return res == no ? no : yes; }; - if constexpr ((NamedQuantitySpec && - NamedQuantitySpec) || - get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) == get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))) + if constexpr ((NamedQuantitySpec && NamedQuantitySpec) || + get_complexity(From{}) == get_complexity(To{})) return convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)); - else if constexpr (get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)) > - get_complexity(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))) + else if constexpr (get_complexity(From{}) > get_complexity(To{})) return exploded_kind_result(convertible_impl( get_kind_tree_root( explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)).quantity), @@ -1405,7 +1402,7 @@ template auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)); if constexpr (NamedQuantitySpec) return convertible_impl(res.quantity, MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); - else if constexpr (requires { MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)._equation_; }) { + else if constexpr (requires { To{}._equation_; }) { auto eq = explode_to_equation(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); return min(eq.result, convertible_impl(res.quantity, eq.equation)); } else @@ -1414,7 +1411,7 @@ template auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); if constexpr (NamedQuantitySpec) return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), res.quantity)); - else if constexpr (requires { MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)._equation_; }) + else if constexpr (requires { From{}._equation_; }) return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)._equation_, res.quantity)); else return min(res.result, are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to))); From eaed0614ef57301887952bd28e97a39f0abfa6dc Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:29:50 +0200 Subject: [PATCH 36/44] [msvc][fix][unit.h] move requires before function signature instead of using MP_UNITS_IS_CONST_EXPR_WORKAROUND --- src/core/include/mp-units/framework/unit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index 7512ba01..83479c49 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -632,8 +632,8 @@ template [[nodiscard]] consteval Unit auto common_unit(Unit auto u) { return u; } template +requires(convertible(U1{}, U2{})) [[nodiscard]] consteval Unit auto common_unit(U1 u1, U2 u2) - requires(convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(u1), MP_UNITS_IS_CONST_EXPR_WORKAROUND(u2))) { if constexpr (is_same_v) return u1; From 52544678c1eaef05bc9864db7febb6f661996bf1 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Mon, 9 Sep 2024 12:37:38 +0200 Subject: [PATCH 37/44] [msvc][fix] add Workaround Macro to conan test-package --- test_package/test_package.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_package/test_package.cpp b/test_package/test_package.cpp index 0ab5bdb0..c941f06d 100644 --- a/test_package/test_package.cpp +++ b/test_package/test_package.cpp @@ -24,11 +24,12 @@ #include #include #include +#include #include using namespace mp_units; -constexpr QuantityOf auto avg_speed(QuantityOf<(isq::distance)> auto d, QuantityOf<(isq::duration)> auto t) +constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) { return d / t; } From 3da6db7d04afddf279c9ece2a61324b6f8dddb36 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:35:55 +0200 Subject: [PATCH 38/44] [msvc][fix] remove all unnecessary MP_UNITS_IS_CONST_EXPR_WORKAROUND --- .../mp-units/framework/quantity_spec.h | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index fee95bb5..6a0bdc2a 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -1342,17 +1342,17 @@ template }; if constexpr ((NamedQuantitySpec && NamedQuantitySpec) || get_complexity(From{}) == get_complexity(To{})) - return convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)); + return convertible_impl(from_kind, to_kind); else if constexpr (get_complexity(From{}) > get_complexity(To{})) return exploded_kind_result(convertible_impl( get_kind_tree_root( - explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind)).quantity), - MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind))); + explode(from_kind).quantity), + to_kind)); else return exploded_kind_result(convertible_impl( - MP_UNITS_IS_CONST_EXPR_WORKAROUND(from_kind), + from_kind, get_kind_tree_root( - explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to_kind)).quantity))); + explode(to_kind).quantity))); } template @@ -1370,11 +1370,11 @@ template else if constexpr (get_complexity(From{}) != get_complexity(To{})) { if constexpr (get_complexity(From{}) > get_complexity(To{})) return convertible_impl( - explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)).quantity, - MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + explode(from).quantity, + to); else { - auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); - return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), res.quantity)); + auto res = explode(to); + return min(res.result, convertible_impl(from, res.quantity)); } } } @@ -1390,31 +1390,30 @@ template else if constexpr (From::dimension != To::dimension) return no; else if constexpr (QuantityKindSpec || QuantityKindSpec) - return convertible_kinds(get_kind_tree_root(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)), - get_kind_tree_root(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to))); + return convertible_kinds(get_kind_tree_root(from), get_kind_tree_root(to)); else if constexpr (NestedQuantityKindSpecOf && get_kind_tree_root(To{}) == To{}) return yes; else if constexpr (NamedQuantitySpec && NamedQuantitySpec) - return convertible_named(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + return convertible_named(from, to); else if constexpr (DerivedQuantitySpec && DerivedQuantitySpec) - return are_ingredients_convertible(from, MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + return are_ingredients_convertible(from, to); else if constexpr (DerivedQuantitySpec) { - auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)); + auto res = explode(from); if constexpr (NamedQuantitySpec) - return convertible_impl(res.quantity, MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); - else if constexpr (requires { To{}._equation_; }) { - auto eq = explode_to_equation(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + return convertible_impl(res.quantity, to); + else if constexpr (requires { to._equation_; }) { + auto eq = explode_to_equation(to); return min(eq.result, convertible_impl(res.quantity, eq.equation)); } else - return are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + return are_ingredients_convertible(from, to); } else if constexpr (DerivedQuantitySpec) { - auto res = explode(MP_UNITS_IS_CONST_EXPR_WORKAROUND(to)); + auto res = explode(to); if constexpr (NamedQuantitySpec) - return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), res.quantity)); - else if constexpr (requires { From{}._equation_; }) - return min(res.result, convertible_impl(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from)._equation_, res.quantity)); + return min(res.result, convertible_impl(from, res.quantity)); + else if constexpr (requires { from._equation_; }) + return min(res.result, convertible_impl(from._equation_, res.quantity)); else - return min(res.result, are_ingredients_convertible(MP_UNITS_IS_CONST_EXPR_WORKAROUND(from), MP_UNITS_IS_CONST_EXPR_WORKAROUND(to))); + return min(res.result, are_ingredients_convertible(from, to)); } // NOLINTEND(bugprone-branch-clone) return no; From ee4a7066cac178784942867d892ee05128041375 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 10 Sep 2024 08:56:52 +0200 Subject: [PATCH 39/44] [msvc][fix] remove MP_UNITS_IS_CONST_EXPR_WORKAROUND --- .../mp-units/bits/get_associated_quantity.h | 4 ++-- src/core/include/mp-units/bits/hacks.h | 3 --- .../mp-units/framework/quantity_spec.h | 24 +++++++------------ .../include/mp-units/framework/reference.h | 4 ++-- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/core/include/mp-units/bits/get_associated_quantity.h b/src/core/include/mp-units/bits/get_associated_quantity.h index d3783b18..d976b17e 100644 --- a/src/core/include/mp-units/bits/get_associated_quantity.h +++ b/src/core/include/mp-units/bits/get_associated_quantity.h @@ -76,9 +76,9 @@ template template [[nodiscard]] consteval auto get_associated_quantity(U u) { - constexpr bool all_kinds = all_are_kinds(MP_UNITS_IS_CONST_EXPR_WORKAROUND(u)); + constexpr bool all_kinds = all_are_kinds(U{}); if constexpr (all_kinds) - return kind_of; + return kind_of; else return get_associated_quantity_impl(u); } diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 4aec2a8d..8ec54946 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -118,15 +118,12 @@ inline constexpr from_range_t from_range{}; #define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) #define MP_UNITS_EXPRESSION_WORKAROUND(x) (x) #define MP_UNITS_IS_VALUE_WORKAROUND(x) (x) -#define MP_UNITS_IS_CONST_EXPR_WORKAROUND(x) \ - decltype(x) {} #else #define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X #define MP_UNITS_EXPRESSION_WORKAROUND(x) x #define MP_UNITS_IS_VALUE_WORKAROUND(x) x -#define MP_UNITS_IS_CONST_EXPR_WORKAROUND(x) x #endif diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 6a0bdc2a..6a3be2ff 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -1345,14 +1345,10 @@ template return convertible_impl(from_kind, to_kind); else if constexpr (get_complexity(From{}) > get_complexity(To{})) return exploded_kind_result(convertible_impl( - get_kind_tree_root( - explode(from_kind).quantity), - to_kind)); + get_kind_tree_root(explode(from_kind).quantity),to_kind)); else - return exploded_kind_result(convertible_impl( - from_kind, - get_kind_tree_root( - explode(to_kind).quantity))); + return exploded_kind_result( + convertible_impl(from_kind,get_kind_tree_root(explode(to_kind).quantity))); } template @@ -1369,11 +1365,9 @@ template return no; else if constexpr (get_complexity(From{}) != get_complexity(To{})) { if constexpr (get_complexity(From{}) > get_complexity(To{})) - return convertible_impl( - explode(from).quantity, - to); + return convertible_impl(explode(from).quantity,to); else { - auto res = explode(to); + auto res = explode(to); return min(res.result, convertible_impl(from, res.quantity)); } } @@ -1398,7 +1392,7 @@ template else if constexpr (DerivedQuantitySpec && DerivedQuantitySpec) return are_ingredients_convertible(from, to); else if constexpr (DerivedQuantitySpec) { - auto res = explode(from); + auto res = explode(from); if constexpr (NamedQuantitySpec) return convertible_impl(res.quantity, to); else if constexpr (requires { to._equation_; }) { @@ -1407,7 +1401,7 @@ template } else return are_ingredients_convertible(from, to); } else if constexpr (DerivedQuantitySpec) { - auto res = explode(to); + auto res = explode(to); if constexpr (NamedQuantitySpec) return min(res.result, convertible_impl(from, res.quantity)); else if constexpr (requires { from._equation_; }) @@ -1498,9 +1492,9 @@ template MP_UNITS_EXPORT_BEGIN template -[[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q q) +[[nodiscard]] consteval detail::QuantityKindSpec auto get_kind(Q) { - return kind_of; + return kind_of; } [[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q) { return q; } diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index 5a5f8262..a708d214 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -292,9 +292,9 @@ template } { return detail::reference_t< - common_quantity_spec(get_quantity_spec(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r1)), get_quantity_spec(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r2)), + common_quantity_spec(get_quantity_spec(R1{}), get_quantity_spec(R2{}), get_quantity_spec(rest)...), - common_unit(get_unit(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r1)), get_unit(MP_UNITS_IS_CONST_EXPR_WORKAROUND(r2)), get_unit(rest)...)>{}; + common_unit(get_unit(R1{}), get_unit(R2{}), get_unit(rest)...)>{}; } MP_UNITS_EXPORT_END From f651438f29cf372580e423bbd4106fa83bc7c0e1 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 10 Sep 2024 09:58:05 +0200 Subject: [PATCH 40/44] [clang-format] --- src/core/include/mp-units/bits/hacks.h | 2 +- src/core/include/mp-units/bits/type_list.h | 26 +++---- src/core/include/mp-units/ext/type_traits.h | 12 +-- .../mp-units/framework/construction_helpers.h | 3 +- .../mp-units/framework/expression_template.h | 11 ++- .../mp-units/framework/quantity_point.h | 6 +- .../mp-units/framework/quantity_spec.h | 14 ++-- .../include/mp-units/framework/reference.h | 29 +++---- src/core/include/mp-units/framework/unit.h | 2 +- src/core/include/mp-units/random.h | 78 +++++++++---------- .../include/mp-units/systems/si/chrono.h | 4 +- .../include/mp-units/systems/si/math.h | 9 ++- test_package/test_package.cpp | 5 +- 13 files changed, 104 insertions(+), 97 deletions(-) diff --git a/src/core/include/mp-units/bits/hacks.h b/src/core/include/mp-units/bits/hacks.h index 8ec54946..2481eb8c 100644 --- a/src/core/include/mp-units/bits/hacks.h +++ b/src/core/include/mp-units/bits/hacks.h @@ -122,7 +122,7 @@ inline constexpr from_range_t from_range{}; #else #define MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(X) X -#define MP_UNITS_EXPRESSION_WORKAROUND(x) x +#define MP_UNITS_EXPRESSION_WORKAROUND(x) x #define MP_UNITS_IS_VALUE_WORKAROUND(x) x #endif diff --git a/src/core/include/mp-units/bits/type_list.h b/src/core/include/mp-units/bits/type_list.h index 61708944..636c1df1 100644 --- a/src/core/include/mp-units/bits/type_list.h +++ b/src/core/include/mp-units/bits/type_list.h @@ -68,7 +68,7 @@ struct type_list_map_impl, To> { }; template typename To> -using type_list_map = type_list_map_impl::type; +using type_list_map = type_list_map_impl::type; // element @@ -105,7 +105,7 @@ struct type_list_front_impl> { }; template -using type_list_front = type_list_front_impl::type; +using type_list_front = type_list_front_impl::type; // back template @@ -121,7 +121,7 @@ struct type_list_push_front_impl, NewTypes...> { }; template -using type_list_push_front = type_list_push_front_impl::type; +using type_list_push_front = type_list_push_front_impl::type; // push_back template @@ -133,7 +133,7 @@ struct type_list_push_back_impl, NewTypes...> { }; template -using type_list_push_back = type_list_push_back_impl::type; +using type_list_push_back = type_list_push_back_impl::type; // join template @@ -143,11 +143,11 @@ struct type_list_join_impl { template typename List, typename... First, typename... Second, typename... Rest> struct type_list_join_impl, List, Rest...> { - using type = type_list_join_impl, Rest...>::type; + using type = type_list_join_impl, Rest...>::type; }; template -using type_list_join = type_list_join_impl::type; +using type_list_join = type_list_join_impl::type; // split template @@ -195,19 +195,19 @@ template typename List, typename Lhs1, typename... LhsRest template typename Pred> requires Pred::value struct type_list_merge_sorted_impl, List, Pred> { - using type = type_list_push_front_impl< + using type = type_list_push_front_impl< typename type_list_merge_sorted_impl, List, Pred>::type, Lhs1>::type; }; template typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest, template typename Pred> struct type_list_merge_sorted_impl, List, Pred> { - using type = type_list_push_front_impl< + using type = type_list_push_front_impl< typename type_list_merge_sorted_impl, List, Pred>::type, Rhs1>::type; }; template typename Pred> -using type_list_merge_sorted = type_list_merge_sorted_impl::type; +using type_list_merge_sorted = type_list_merge_sorted_impl::type; // sort template typename Pred> @@ -227,13 +227,13 @@ template typename List, typename... Types, template, Pred> { using types = List; using split = type_list_split_half>; - using sorted_left = type_list_sort_impl::type; - using sorted_right = type_list_sort_impl::type; - using type = type_list_merge_sorted_impl::type; + using sorted_left = type_list_sort_impl::type; + using sorted_right = type_list_sort_impl::type; + using type = type_list_merge_sorted_impl::type; }; template typename Pred> -using type_list_sort = type_list_sort_impl::type; +using type_list_sort = type_list_sort_impl::type; } // namespace mp_units::detail diff --git a/src/core/include/mp-units/ext/type_traits.h b/src/core/include/mp-units/ext/type_traits.h index 77f0267b..2ee78e2a 100644 --- a/src/core/include/mp-units/ext/type_traits.h +++ b/src/core/include/mp-units/ext/type_traits.h @@ -56,7 +56,7 @@ struct conditional_impl { MP_UNITS_EXPORT_BEGIN template -using conditional = detail::conditional_impl::template type; +using conditional = detail::conditional_impl::template type; // is_same template @@ -98,7 +98,7 @@ namespace detail { template struct get_value_type { - using type = T::value_type; + using type = T::value_type; }; template @@ -111,13 +111,13 @@ struct get_element_type { template requires requires { typename T::value_type; } || requires { typename T::element_type; } struct wrapped_type { - using type = + using type = conditional, detail::get_element_type>::type; }; template requires requires { typename T::value_type; } || requires { typename T::element_type; } -using wrapped_type_t = wrapped_type::type; +using wrapped_type_t = wrapped_type::type; template struct value_type { @@ -127,11 +127,11 @@ struct value_type { template requires requires { typename wrapped_type_t; } struct value_type { - using type = wrapped_type_t; + using type = wrapped_type_t; }; template -using value_type_t = value_type::type; +using value_type_t = value_type::type; template concept one_of = (false || ... || std::same_as); diff --git a/src/core/include/mp-units/framework/construction_helpers.h b/src/core/include/mp-units/framework/construction_helpers.h index cc83946b..43eade94 100644 --- a/src/core/include/mp-units/framework/construction_helpers.h +++ b/src/core/include/mp-units/framework/construction_helpers.h @@ -49,7 +49,8 @@ struct delta_ { template struct absolute_ { template Rep = std::remove_cvref_t> - [[nodiscard]] constexpr quantity_point operator()(FwdRep&& lhs) const + [[nodiscard]] constexpr quantity_point + operator()(FwdRep&& lhs) const { return quantity_point{quantity{std::forward(lhs), R{}}}; } diff --git a/src/core/include/mp-units/framework/expression_template.h b/src/core/include/mp-units/framework/expression_template.h index 6b5836ff..45d3d4b6 100644 --- a/src/core/include/mp-units/framework/expression_template.h +++ b/src/core/include/mp-units/framework/expression_template.h @@ -122,7 +122,7 @@ struct expr_type_impl> : std::type_identity {}; } // namespace detail template -using expr_type = detail::expr_type_impl::type; +using expr_type = detail::expr_type_impl::type; namespace detail { @@ -182,25 +182,24 @@ struct expr_consolidate_impl> { template requires(!is_specialization_of_power) struct expr_consolidate_impl> { - using type = expr_consolidate_impl, Rest...>>::type; + using type = expr_consolidate_impl, Rest...>>::type; }; // replaces the instance of a type and a power of it with one with incremented power template struct expr_consolidate_impl, Rest...>> { - using type = - expr_consolidate_impl::exponent + 1>, Rest...>>::type; + using type = expr_consolidate_impl::exponent + 1>, Rest...>>::type; }; // accumulates the powers of instances of the same type (removes the element in case the accumulation result is `0`) template struct expr_consolidate_impl, power, Rest...>> { static constexpr ratio r = power::exponent + power::exponent; - using type = expr_consolidate_impl, Rest...>>::type; + using type = expr_consolidate_impl, Rest...>>::type; }; template -using expr_consolidate = expr_consolidate_impl::type; +using expr_consolidate = expr_consolidate_impl::type; /** diff --git a/src/core/include/mp-units/framework/quantity_point.h b/src/core/include/mp-units/framework/quantity_point.h index 13d0bd2f..074cd8fa 100644 --- a/src/core/include/mp-units/framework/quantity_point.h +++ b/src/core/include/mp-units/framework/quantity_point.h @@ -53,13 +53,15 @@ template struct point_origin_interface { template Q = std::remove_cvref_t> - [[nodiscard]] friend constexpr quantity_point operator+(PO, FwdQ&& q) + [[nodiscard]] friend constexpr quantity_point + operator+(PO, FwdQ&& q) { return quantity_point{std::forward(q), PO{}}; } template Q = std::remove_cvref_t> - [[nodiscard]] friend constexpr quantity_point operator+(FwdQ&& q, PO po) + [[nodiscard]] friend constexpr quantity_point + operator+(FwdQ&& q, PO po) { return po + std::forward(q); } diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 6a3be2ff..7672ba02 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -667,11 +667,11 @@ template // dimension_one is always the last one // otherwise, sort by typename template -[[nodiscard]] consteval bool ingredients_dimension_less(D1 lhs, D2 rhs) +[[nodiscard]] consteval bool ingredients_dimension_less(D1, D2) { if constexpr (D1{} == D2{} || D1{} == dimension_one) return false; - else if constexpr (D2{} == dimension_one) + else if constexpr (D2{} == dimension_one) return true; else return detail::type_name() < detail::type_name(); @@ -684,7 +684,7 @@ struct ingredients_less : std::bool_constant<(lhs_compl > rhs_compl) || (lhs_compl == rhs_compl && ingredients_dimension_less(Lhs::dimension, Rhs::dimension)) || (lhs_compl == rhs_compl && Lhs::dimension == Rhs::dimension && - detail::type_name() < detail::type_name())> {}; + detail::type_name() < detail::type_name())>{}; template using type_list_of_ingredients_less = expr_less; @@ -1344,11 +1344,11 @@ template get_complexity(From{}) == get_complexity(To{})) return convertible_impl(from_kind, to_kind); else if constexpr (get_complexity(From{}) > get_complexity(To{})) - return exploded_kind_result(convertible_impl( - get_kind_tree_root(explode(from_kind).quantity),to_kind)); + return exploded_kind_result( + convertible_impl(get_kind_tree_root(explode(from_kind).quantity), to_kind)); else return exploded_kind_result( - convertible_impl(from_kind,get_kind_tree_root(explode(to_kind).quantity))); + convertible_impl(from_kind, get_kind_tree_root(explode(to_kind).quantity))); } template @@ -1365,7 +1365,7 @@ template return no; else if constexpr (get_complexity(From{}) != get_complexity(To{})) { if constexpr (get_complexity(From{}) > get_complexity(To{})) - return convertible_impl(explode(from).quantity,to); + return convertible_impl(explode(from).quantity, to); else { auto res = explode(to); return min(res.result, convertible_impl(from, res.quantity)); diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index a708d214..ea19739d 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -87,46 +87,48 @@ struct reference { } template - [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} * Q2{}), MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> + [[nodiscard]] friend consteval detail::reference_t operator*(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t<( MP_UNITS_EXPRESSION_WORKAROUND(Q{} * get_quantity_spec(U2{}))), - MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> + [[nodiscard]] friend consteval detail::reference_t<(MP_UNITS_EXPRESSION_WORKAROUND(Q{} * get_quantity_spec(U2{}))), + MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> operator*(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) * Q{}), - MP_UNITS_EXPRESSION_WORKAROUND(U1{} * U{})> + [[nodiscard]] friend consteval detail::reference_t operator*(U1, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} / Q2{}), MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})> + [[nodiscard]] friend consteval detail::reference_t operator/(reference, reference) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} / get_quantity_spec(U2{})), - MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})> + [[nodiscard]] friend consteval detail::reference_t operator/(reference, U2) { return {}; } template - [[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) / Q{}), - MP_UNITS_EXPRESSION_WORKAROUND(U1{} / U{})> + [[nodiscard]] friend consteval detail::reference_t operator/(U1, reference) { return {}; @@ -291,10 +293,9 @@ template } -> Unit; } { - return detail::reference_t< - common_quantity_spec(get_quantity_spec(R1{}), get_quantity_spec(R2{}), - get_quantity_spec(rest)...), - common_unit(get_unit(R1{}), get_unit(R2{}), get_unit(rest)...)>{}; + return detail::reference_t{}; } MP_UNITS_EXPORT_END diff --git a/src/core/include/mp-units/framework/unit.h b/src/core/include/mp-units/framework/unit.h index 83479c49..332586eb 100644 --- a/src/core/include/mp-units/framework/unit.h +++ b/src/core/include/mp-units/framework/unit.h @@ -632,7 +632,7 @@ template [[nodiscard]] consteval Unit auto common_unit(Unit auto u) { return u; } template -requires(convertible(U1{}, U2{})) + requires(convertible(U1{}, U2{})) [[nodiscard]] consteval Unit auto common_unit(U1 u1, U2 u2) { if constexpr (is_same_v) diff --git a/src/core/include/mp-units/random.h b/src/core/include/mp-units/random.h index 05251f3f..5da89966 100644 --- a/src/core/include/mp-units/random.h +++ b/src/core/include/mp-units/random.h @@ -61,7 +61,7 @@ std::vector bl_qty_to_rep(std::initializer_list& bl) template std::vector fw_bl_pwc(std::initializer_list& bl, UnaryOperation fw) { - using rep = Q::rep; + using rep = Q::rep; std::vector w_bl; w_bl.reserve(bl.size()); for (const Q& qty : bl) { @@ -93,8 +93,8 @@ MP_UNITS_EXPORT_BEGIN template requires std::integral struct uniform_int_distribution : public std::uniform_int_distribution { - using rep = Q::rep; - using base = std::uniform_int_distribution; + using rep = Q::rep; + using base = std::uniform_int_distribution; uniform_int_distribution() : base() {} uniform_int_distribution(const Q& a, const Q& b) : @@ -118,8 +118,8 @@ struct uniform_int_distribution : public std::uniform_int_distribution requires std::floating_point struct uniform_real_distribution : public std::uniform_real_distribution { - using rep = Q::rep; - using base = std::uniform_real_distribution; + using rep = Q::rep; + using base = std::uniform_real_distribution; uniform_real_distribution() : base() {} uniform_real_distribution(const Q& a, const Q& b) : @@ -143,8 +143,8 @@ struct uniform_real_distribution : public std::uniform_real_distribution requires std::integral struct binomial_distribution : public std::binomial_distribution { - using rep = Q::rep; - using base = std::binomial_distribution; + using rep = Q::rep; + using base = std::binomial_distribution; binomial_distribution() : base() {} binomial_distribution(const Q& t, double p) : base(t.numerical_value_ref_in(Q::unit), p) {} @@ -164,8 +164,8 @@ struct binomial_distribution : public std::binomial_distribution requires std::integral struct negative_binomial_distribution : public std::negative_binomial_distribution { - using rep = Q::rep; - using base = std::negative_binomial_distribution; + using rep = Q::rep; + using base = std::negative_binomial_distribution; negative_binomial_distribution() : base() {} negative_binomial_distribution(const Q& k, double p) : base(k.numerical_value_ref_in(Q::unit), p) {} @@ -185,8 +185,8 @@ struct negative_binomial_distribution : public std::negative_binomial_distributi template requires std::integral struct geometric_distribution : public std::geometric_distribution { - using rep = Q::rep; - using base = std::geometric_distribution; + using rep = Q::rep; + using base = std::geometric_distribution; geometric_distribution() : base() {} explicit geometric_distribution(double p) : base(p) {} @@ -204,8 +204,8 @@ struct geometric_distribution : public std::geometric_distribution requires std::integral struct poisson_distribution : public std::poisson_distribution { - using rep = Q::rep; - using base = std::poisson_distribution; + using rep = Q::rep; + using base = std::poisson_distribution; poisson_distribution() : base() {} explicit poisson_distribution(double p) : base(p) {} @@ -223,8 +223,8 @@ struct poisson_distribution : public std::poisson_distribution template requires std::floating_point struct exponential_distribution : public std::exponential_distribution { - using rep = Q::rep; - using base = std::exponential_distribution; + using rep = Q::rep; + using base = std::exponential_distribution; exponential_distribution() : base() {} explicit exponential_distribution(const rep& lambda) : base(lambda) {} @@ -242,8 +242,8 @@ struct exponential_distribution : public std::exponential_distribution requires std::floating_point struct gamma_distribution : public std::gamma_distribution { - using rep = Q::rep; - using base = std::gamma_distribution; + using rep = Q::rep; + using base = std::gamma_distribution; gamma_distribution() : base() {} gamma_distribution(const rep& alpha, const rep& beta) : base(alpha, beta) {} @@ -261,8 +261,8 @@ struct gamma_distribution : public std::gamma_distribution { template requires std::floating_point struct weibull_distribution : public std::weibull_distribution { - using rep = Q::rep; - using base = std::weibull_distribution; + using rep = Q::rep; + using base = std::weibull_distribution; weibull_distribution() : base() {} weibull_distribution(const rep& a, const rep& b) : base(a, b) {} @@ -280,8 +280,8 @@ struct weibull_distribution : public std::weibull_distribution template requires std::floating_point struct extreme_value_distribution : public std::extreme_value_distribution { - using rep = Q::rep; - using base = std::extreme_value_distribution; + using rep = Q::rep; + using base = std::extreme_value_distribution; extreme_value_distribution() : base() {} extreme_value_distribution(const Q& a, const rep& b) : base(a.numerical_value_ref_in(Q::unit), b) {} @@ -301,8 +301,8 @@ struct extreme_value_distribution : public std::extreme_value_distribution requires std::floating_point struct normal_distribution : public std::normal_distribution { - using rep = Q::rep; - using base = std::normal_distribution; + using rep = Q::rep; + using base = std::normal_distribution; normal_distribution() : base() {} normal_distribution(const Q& mean, const Q& stddev) : @@ -326,8 +326,8 @@ struct normal_distribution : public std::normal_distribution { template requires std::floating_point struct lognormal_distribution : public std::lognormal_distribution { - using rep = Q::rep; - using base = std::lognormal_distribution; + using rep = Q::rep; + using base = std::lognormal_distribution; lognormal_distribution() : base() {} lognormal_distribution(const Q& m, const Q& s) : @@ -351,8 +351,8 @@ struct lognormal_distribution : public std::lognormal_distribution requires std::floating_point struct chi_squared_distribution : public std::chi_squared_distribution { - using rep = Q::rep; - using base = std::chi_squared_distribution; + using rep = Q::rep; + using base = std::chi_squared_distribution; chi_squared_distribution() : base() {} explicit chi_squared_distribution(const rep& n) : base(n) {} @@ -370,8 +370,8 @@ struct chi_squared_distribution : public std::chi_squared_distribution requires std::floating_point struct cauchy_distribution : public std::cauchy_distribution { - using rep = Q::rep; - using base = std::cauchy_distribution; + using rep = Q::rep; + using base = std::cauchy_distribution; cauchy_distribution() : base() {} cauchy_distribution(const Q& a, const Q& b) : @@ -395,8 +395,8 @@ struct cauchy_distribution : public std::cauchy_distribution { template requires std::floating_point struct fisher_f_distribution : public std::fisher_f_distribution { - using rep = Q::rep; - using base = std::fisher_f_distribution; + using rep = Q::rep; + using base = std::fisher_f_distribution; fisher_f_distribution() : base() {} fisher_f_distribution(const rep& m, const rep& n) : base(m, n) {} @@ -414,8 +414,8 @@ struct fisher_f_distribution : public std::fisher_f_distribution requires std::floating_point struct student_t_distribution : public std::student_t_distribution { - using rep = Q::rep; - using base = std::student_t_distribution; + using rep = Q::rep; + using base = std::student_t_distribution; student_t_distribution() : base() {} explicit student_t_distribution(const rep& n) : base(n) {} @@ -433,8 +433,8 @@ struct student_t_distribution : public std::student_t_distribution requires std::integral struct discrete_distribution : public std::discrete_distribution { - using rep = Q::rep; - using base = std::discrete_distribution; + using rep = Q::rep; + using base = std::discrete_distribution; discrete_distribution() : base() {} @@ -464,8 +464,8 @@ struct discrete_distribution : public std::discrete_distribution requires std::floating_point class piecewise_constant_distribution : public std::piecewise_constant_distribution { - using rep = Q::rep; - using base = std::piecewise_constant_distribution; + using rep = Q::rep; + using base = std::piecewise_constant_distribution; template piecewise_constant_distribution(const std::vector& i, InputIt first_w) : base(i.cbegin(), i.cend(), first_w) @@ -523,8 +523,8 @@ public: template requires std::floating_point class piecewise_linear_distribution : public std::piecewise_linear_distribution { - using rep = Q::rep; - using base = std::piecewise_linear_distribution; + using rep = Q::rep; + using base = std::piecewise_linear_distribution; template piecewise_linear_distribution(const std::vector& i, InputIt first_w) : base(i.cbegin(), i.cend(), first_w) diff --git a/src/systems/include/mp-units/systems/si/chrono.h b/src/systems/include/mp-units/systems/si/chrono.h index c3fb9707..0ded9689 100644 --- a/src/systems/include/mp-units/systems/si/chrono.h +++ b/src/systems/include/mp-units/systems/si/chrono.h @@ -137,8 +137,8 @@ template QP> requires is_specialization_of, chrono_point_origin_> [[nodiscard]] constexpr auto to_chrono_time_point(const QP& qp) { - using clock = decltype(QP::absolute_point_origin)::clock; - using rep = QP::rep; + using clock = decltype(QP::absolute_point_origin)::clock; + using rep = QP::rep; using ret_type = std::chrono::time_point>; diff --git a/src/systems/include/mp-units/systems/si/math.h b/src/systems/include/mp-units/systems/si/math.h index c91d0df8..80568e37 100644 --- a/src/systems/include/mp-units/systems/si/math.h +++ b/src/systems/include/mp-units/systems/si/math.h @@ -87,7 +87,8 @@ template auto R, template auto R, typename Rep> requires requires(Rep v) { asin(v); } || requires(Rep v) { std::asin(v); } -[[nodiscard]] inline QuantityOf auto asin(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto asin( + const quantity& q) noexcept { using std::asin; if constexpr (!treat_as_floating_point) { @@ -101,7 +102,8 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { acos(v); } || requires(Rep v) { std::acos(v); } -[[nodiscard]] inline QuantityOf auto acos(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto acos( + const quantity& q) noexcept { using std::acos; if constexpr (!treat_as_floating_point) { @@ -115,7 +117,8 @@ template auto R, typename Rep> template auto R, typename Rep> requires requires(Rep v) { atan(v); } || requires(Rep v) { std::atan(v); } -[[nodiscard]] inline QuantityOf auto atan(const quantity& q) noexcept +[[nodiscard]] inline QuantityOf auto atan( + const quantity& q) noexcept { using std::atan; if constexpr (!treat_as_floating_point) { diff --git a/test_package/test_package.cpp b/test_package/test_package.cpp index c941f06d..e676162f 100644 --- a/test_package/test_package.cpp +++ b/test_package/test_package.cpp @@ -20,16 +20,17 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include #include #include #include #include -#include #include using namespace mp_units; -constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) +constexpr QuantityOf auto avg_speed(QuantityOf auto d, + QuantityOf auto t) { return d / t; } From 413966efca3dae9bd320fb45253c1119a5acb68b Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:03:37 +0200 Subject: [PATCH 41/44] [msvc][fix] revert changes in example and test folder --- example/avg_speed.cpp | 12 +- example/capacitor_time_curve.cpp | 2 +- example/clcpp_response.cpp | 4 +- example/currency.cpp | 14 +- example/glide_computer.cpp | 10 +- .../include/glide_computer_lib.h | 2 +- example/hello_units.cpp | 2 +- example/include/geographic.h | 8 +- example/kalman_filter/kalman.h | 16 +- example/measurement.cpp | 2 +- example/spectroscopy_units.cpp | 8 +- example/storage_tank.cpp | 10 +- example/total_energy.cpp | 18 +- example/unmanned_aerial_vehicle.cpp | 1 - test/runtime/CMakeLists.txt | 10 +- test/static/chrono_test.cpp | 85 +- test/static/concepts_test.cpp | 242 +++--- test/static/custom_rep_test_min_impl.cpp | 67 +- test/static/dimension_test.cpp | 2 +- test/static/quantity_point_test.cpp | 795 +++++++++--------- test/static/quantity_spec_test.cpp | 4 +- test/static/quantity_test.cpp | 204 +++-- test/static/reference_test.cpp | 6 +- test/static/si_test.cpp | 2 +- test/static/unit_test.cpp | 4 +- 25 files changed, 759 insertions(+), 771 deletions(-) diff --git a/example/avg_speed.cpp b/example/avg_speed.cpp index 11072bb3..dc2d24d2 100644 --- a/example/avg_speed.cpp +++ b/example/avg_speed.cpp @@ -45,26 +45,26 @@ namespace { using namespace mp_units; -constexpr quantity fixed_int_si_avg_speed(quantity<(si::metre), int> d, - quantity<(si::second), int> t) +constexpr quantity fixed_int_si_avg_speed(quantity d, + quantity t) { return d / t; } -constexpr quantity fixed_double_si_avg_speed(quantity<(si::metre)> d, quantity<(si::second)> t) +constexpr quantity fixed_double_si_avg_speed(quantity d, quantity t) { return d / t; } -constexpr QuantityOf<(isq::speed)> auto avg_speed(QuantityOf<(isq::length)> auto d, QuantityOf<(isq::time)> auto t) +constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) { return d / t; } -template D, QuantityOf<(isq::time)> T, QuantityOf<(isq::speed)> V> +template D, QuantityOf T, QuantityOf V> void print_result(D distance, T duration, V speed) { - const auto result_in_kmph = speed.force_in((si::kilo<(si::metre)> / non_si::hour)); + const auto result_in_kmph = speed.force_in(si::kilo / non_si::hour); std::cout << "Average speed of a car that makes " << distance << " in " << duration << " is " << result_in_kmph << ".\n"; } diff --git a/example/capacitor_time_curve.cpp b/example/capacitor_time_curve.cpp index 2f2f7fdb..4cf363fe 100644 --- a/example/capacitor_time_curve.cpp +++ b/example/capacitor_time_curve.cpp @@ -48,7 +48,7 @@ int main() constexpr auto RR = isq::resistance(4.7 * si::kilo); for (auto tt = 0 * ms; tt <= 50 * ms; ++tt) { - const QuantityOf<(isq::voltage)> auto Vt = V0 * exp(dimensionless(-tt / (RR * CC))); + const QuantityOf auto Vt = V0 * exp(dimensionless(-tt / (RR * CC))); // TODO try to make the below work instead // const QuantityOf auto Vt = V0 * exp(-tt / (RR * CC)); diff --git a/example/clcpp_response.cpp b/example/clcpp_response.cpp index 9a74de52..42ed6d0b 100644 --- a/example/clcpp_response.cpp +++ b/example/clcpp_response.cpp @@ -44,8 +44,8 @@ void simple_quantities() using namespace mp_units::si; using namespace mp_units::international; - using distance = quantity<(isq::distance[kilo])>; - using duration = quantity<(isq::duration[second])>; + using distance = quantity]>; + using duration = quantity; constexpr distance km = 1. * kilo; constexpr distance miles = 1. * mile; diff --git a/example/currency.cpp b/example/currency.cpp index 0eb46040..6f280659 100644 --- a/example/currency.cpp +++ b/example/currency.cpp @@ -90,11 +90,11 @@ template #endif -// template auto To, ReferenceOf auto From, typename Rep> -// quantity exchange_to(quantity q) -// { -// return static_cast(exchange_rate() * q.numerical_value()) * To; -// } +template auto To, ReferenceOf auto From, typename Rep> +quantity exchange_to(quantity q) +{ + return static_cast(exchange_rate() * q.numerical_value()) * To; +} template auto To, ReferenceOf auto From, auto PO, typename Rep> quantity_point exchange_to(quantity_point q) @@ -107,8 +107,8 @@ int main() { using namespace unit_symbols; - const mp_units::quantity_point price_usd{100 * USD}; - const mp_units::quantity_point price_euro = exchange_to(price_usd); + const quantity_point price_usd{100 * USD}; + const quantity_point price_euro = exchange_to(price_usd); std::cout << price_usd.quantity_from_zero() << " -> " << price_euro.quantity_from_zero() << "\n"; // std::cout << price_usd.quantity_from_zero() + price_euro.quantity_from_zero() << "\n"; // does diff --git a/example/glide_computer.cpp b/example/glide_computer.cpp index f06062fe..133a7713 100644 --- a/example/glide_computer.cpp +++ b/example/glide_computer.cpp @@ -169,7 +169,7 @@ void example() const auto gliders = get_gliders(); const auto waypoints = get_waypoints(); const auto weather_conditions = get_weather_conditions(); - const task glider_task = {waypoints[0], waypoints[1], waypoints[0]}; + const task t = {waypoints[0], waypoints[1], waypoints[0]}; const aircraft_tow tow = {400 * m, 1.6 * m / s}; const timestamp start_time(std::chrono::system_clock::now()); @@ -177,16 +177,16 @@ void example() print(gliders); print(waypoints); print(weather_conditions); - print(glider_task); + print(t); print(tow); - for (const auto& glider : gliders) { + for (const auto& g : gliders) { for (const auto& c : weather_conditions) { - const std::string txt = "Scenario: Glider = " + glider.name + ", Weather = " + c.first; + const std::string txt = "Scenario: Glider = " + g.name + ", Weather = " + c.first; std::cout << txt << "\n"; std::cout << MP_UNITS_STD_FMT::format("{0:=^{1}}\n\n", "", txt.size()); - estimate(start_time, glider, c.second, glider_task, sfty, tow); + estimate(start_time, g, c.second, t, sfty, tow); std::cout << "\n\n"; } diff --git a/example/glide_computer_lib/include/glide_computer_lib.h b/example/glide_computer_lib/include/glide_computer_lib.h index e8fafbf3..5e2ac4db 100644 --- a/example/glide_computer_lib/include/glide_computer_lib.h +++ b/example/glide_computer_lib/include/glide_computer_lib.h @@ -90,7 +90,7 @@ struct glider { std::array polar; }; -constexpr mp_units::QuantityOf<(mp_units::dimensionless)> auto glide_ratio(const glider::polar_point& polar) +constexpr mp_units::QuantityOf auto glide_ratio(const glider::polar_point& polar) { return polar.v / -polar.climb; } diff --git a/example/hello_units.cpp b/example/hello_units.cpp index 95b5e6d6..e635bc25 100644 --- a/example/hello_units.cpp +++ b/example/hello_units.cpp @@ -45,7 +45,7 @@ import mp_units; using namespace mp_units; -constexpr QuantityOf<(isq::speed)> auto avg_speed(QuantityOf<(isq::length)> auto d, QuantityOf<(isq::time)> auto t) +constexpr QuantityOf auto avg_speed(QuantityOf auto d, QuantityOf auto t) { return d / t; } diff --git a/example/include/geographic.h b/example/include/geographic.h index 4f7ca94a..ba26b3f1 100644 --- a/example/include/geographic.h +++ b/example/include/geographic.h @@ -79,10 +79,10 @@ inline constexpr struct prime_meridian final : mp_units::absolute_point_origin -using latitude = mp_units::quantity_point<(mp_units::si::degree), equator, ranged_representation>; +using latitude = mp_units::quantity_point>; template -using longitude = mp_units::quantity_point<(mp_units::si::degree), prime_meridian, ranged_representation>; +using longitude = mp_units::quantity_point>; template std::basic_ostream& operator<<(std::basic_ostream& os, const latitude& lat) @@ -176,7 +176,7 @@ template distance spherical_distance(position from, position to) { using namespace mp_units; - constexpr quantity earth_radius = 6'371 * isq::radius[si::kilo<(si::metre)>]; + constexpr quantity earth_radius = 6'371 * isq::radius[si::kilo]; using si::sin, si::cos, si::asin, si::acos; @@ -193,7 +193,7 @@ distance spherical_distance(position from, position to) // const auto central_angle = 2 * asin(sqrt(0.5 - cos(to_lat - from_lat) / 2 + cos(from_lat) * cos(to_lat) * (1 // - cos(lon2_rad - from_lon)) / 2)); - return quantity_cast<(isq::distance)>(earth_radius * central_angle); + return quantity_cast(earth_radius * central_angle); } else { // the haversine formula const quantity sin_lat = sin((to_lat - from_lat) / 2); diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index 80179790..90d0d506 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -116,15 +116,15 @@ template } // state update -template K> +template K> requires(implicitly_convertible(QM::quantity_spec, QP::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, K gain) { return system_state{get<0>(predicted) + gain * (measured - get<0>(predicted))}; } -template K, - mp_units::QuantityOf<(mp_units::isq::time)> T> +template K, + mp_units::QuantityOf T> requires(implicitly_convertible(QM::quantity_spec, QP1::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, std::array gain, T interval) @@ -135,7 +135,7 @@ template K, mp_units::QuantityOf<(mp_units::isq::time)> T> + mp_units::QuantityOf K, mp_units::QuantityOf T> requires(implicitly_convertible(QM::quantity_spec, QP1::quantity_spec)) [[nodiscard]] constexpr system_state state_update(const system_state& predicted, QM measured, std::array gain, T interval) @@ -147,13 +147,13 @@ template K> +template K> [[nodiscard]] constexpr Q covariance_update(Q uncertainty, K gain) { return (1 * mp_units::one - gain) * uncertainty; } -template K> +template K> [[nodiscard]] constexpr system_state_estimate state_estimate_update( const system_state_estimate& previous, QP measurement, K gain) { @@ -162,7 +162,7 @@ template T> +template T> [[nodiscard]] constexpr system_state state_extrapolation(const system_state& estimated, T interval) { auto to_quantity = [](const auto& qp) { return qp.quantity_ref_from(qp.point_origin); }; @@ -171,7 +171,7 @@ template return system_state{qp1, qp2}; } -template T> +template T> [[nodiscard]] constexpr system_state state_extrapolation(const system_state& estimated, T interval) { diff --git a/example/measurement.cpp b/example/measurement.cpp index d7650c21..d61c8d2e 100644 --- a/example/measurement.cpp +++ b/example/measurement.cpp @@ -151,7 +151,7 @@ void example() const auto acceleration = isq::acceleration(measurement{9.8, 0.1} * m / s2); const auto time = measurement{1.2, 0.1} * s; - const QuantityOf<(isq::velocity)> auto velocity = acceleration * time; + const MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(QuantityOf) auto velocity = acceleration * time; std::cout << acceleration << " * " << time << " = " << velocity << " = " << velocity.in(km / h) << '\n'; const auto length = measurement{123., 1.} * m; diff --git a/example/spectroscopy_units.cpp b/example/spectroscopy_units.cpp index d618b3b3..3fce6a8b 100644 --- a/example/spectroscopy_units.cpp +++ b/example/spectroscopy_units.cpp @@ -54,8 +54,8 @@ constexpr auto h = 1 * si::si2019::planck_constant; constexpr auto kb = 1 * si::si2019::boltzmann_constant; // prints quantities in the resulting unit -template T1, QuantityOf<(isq::wavenumber)> T2, QuantityOf<(isq::frequency)> T3, - QuantityOf<(isq::thermodynamic_temperature)> T4, QuantityOf<(isq::wavelength)> T5> +template T1, QuantityOf T2, QuantityOf T3, + QuantityOf T4, QuantityOf T5> void print_line(const std::tuple& t) { std::cout << MP_UNITS_STD_FMT::format( @@ -65,8 +65,8 @@ void print_line(const std::tuple& t) // prints quantities in semi-SI units // (eV is not an official SI unit) -template T1, QuantityOf<(isq::wavenumber)> T2, QuantityOf<(isq::frequency)> T3, - QuantityOf<(isq::thermodynamic_temperature)> T4, QuantityOf<(isq::wavelength)> T5> +template T1, QuantityOf T2, QuantityOf T3, + QuantityOf T4, QuantityOf T5> void print_line_si(const std::tuple& t) { std::cout << MP_UNITS_STD_FMT::format( diff --git a/example/storage_tank.cpp b/example/storage_tank.cpp index 44b24738..86bc32ff 100644 --- a/example/storage_tank.cpp +++ b/example/storage_tank.cpp @@ -77,10 +77,10 @@ public: density_ = density; } - [[nodiscard]] constexpr QuantityOf<(isq::weight)> auto filled_weight() const + [[nodiscard]] constexpr QuantityOf auto filled_weight() const { const auto volume = isq::volume(base_ * height_); // TODO check if we can remove that cast - const QuantityOf<(isq::mass)> auto mass = density_ * volume; + const QuantityOf auto mass = density_ * volume; return isq::weight(mass * g); } @@ -130,9 +130,9 @@ int main() const quantity spare_capacity = tank.spare_capacity(measured_mass); const quantity filled_weight = tank.filled_weight(); - const QuantityOf<(isq::mass_change_rate)> auto input_flow_rate = measured_mass / fill_time; - const QuantityOf<(isq::speed)> auto float_rise_rate = fill_level / fill_time; - const QuantityOf<(isq::time)> auto fill_time_left = (height / fill_level - 1 * one) * fill_time; + const QuantityOf auto input_flow_rate = measured_mass / fill_time; + const QuantityOf auto float_rise_rate = fill_level / fill_time; + const QuantityOf auto fill_time_left = (height / fill_level - 1 * one) * fill_time; const quantity fill_ratio = fill_level / height; diff --git a/example/total_energy.cpp b/example/total_energy.cpp index 28963f6b..75416bb7 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -45,8 +45,8 @@ namespace { using namespace mp_units; -QuantityOf<(isq::mechanical_energy)> auto total_energy(QuantityOf<(isq::momentum)> auto p, - QuantityOf<(isq::mass)> auto m, QuantityOf<(isq::speed)> auto c) +QuantityOf auto total_energy(QuantityOf auto p, QuantityOf auto m, + QuantityOf auto c) { return isq::mechanical_energy(sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c)))); } @@ -59,19 +59,19 @@ void si_example() const quantity c2 = pow<2>(c); const quantity p1 = isq::momentum(4. * GeV / c); - const QuantityOf<(isq::mass)> auto m1 = 3. * GeV / c2; - const quantity E1 = total_energy(p1, m1, c); + const QuantityOf auto m1 = 3. * GeV / c2; + const quantity E = total_energy(p1, m1, c); std::cout << "\n*** SI units (c = " << c << " = " << c.in(si::metre / s) << ") ***\n"; std::cout << "\n[in `GeV` and `c`]\n" << "p = " << p1 << "\n" << "m = " << m1 << "\n" - << "E = " << E1 << "\n"; + << "E = " << E << "\n"; const quantity p2 = p1.in(GeV / (m / s)); - const quantity metre2 = m1.in(GeV / pow<2>(m / s)); - const quantity E2 = total_energy(p2, metre2, c).in(GeV); + const quantity m2 = m1.in(GeV / pow<2>(m / s)); + const quantity E2 = total_energy(p2, m2, c).in(GeV); std::cout << "\n[in `GeV`]\n" << "p = " << p2 << "\n" @@ -79,8 +79,8 @@ void si_example() << "E = " << E2 << "\n"; const quantity p3 = p1.in(kg * m / s); - const quantity metre3 = m1.in(kg); - const quantity E3 = total_energy(p3, metre3, c).in(J); + const quantity m3 = m1.in(kg); + const quantity E3 = total_energy(p3, m3, c).in(J); std::cout << "\n[in SI base units]\n" << "p = " << p3 << "\n" diff --git a/example/unmanned_aerial_vehicle.cpp b/example/unmanned_aerial_vehicle.cpp index 9cb32bfc..064e8055 100644 --- a/example/unmanned_aerial_vehicle.cpp +++ b/example/unmanned_aerial_vehicle.cpp @@ -70,7 +70,6 @@ constexpr const char* to_text(earth_gravity_model m) return "EGM2008-1"; } assert(false && "unsupported enum value"); - return "unsupported enum value"; } template diff --git a/test/runtime/CMakeLists.txt b/test/runtime/CMakeLists.txt index 70e13650..d79ed54b 100644 --- a/test/runtime/CMakeLists.txt +++ b/test/runtime/CMakeLists.txt @@ -37,11 +37,11 @@ if(${projectPrefix}BUILD_CXX_MODULES) endif() target_link_libraries(unit_tests_runtime PRIVATE mp-units::mp-units Catch2::Catch2WithMain) -# if(${projectPrefix}DEV_BUILD_LA) -# find_package(wg21_linear_algebra REQUIRED) -# target_sources(unit_tests_runtime PRIVATE linear_algebra_test.cpp) -# target_link_libraries(unit_tests_runtime PRIVATE wg21_linear_algebra::wg21_linear_algebra) -# endif() +if(${projectPrefix}DEV_BUILD_LA) + find_package(wg21_linear_algebra REQUIRED) + target_sources(unit_tests_runtime PRIVATE linear_algebra_test.cpp) + target_link_libraries(unit_tests_runtime PRIVATE wg21_linear_algebra::wg21_linear_algebra) +endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options( diff --git a/test/static/chrono_test.cpp b/test/static/chrono_test.cpp index 2785041f..8c532390 100644 --- a/test/static/chrono_test.cpp +++ b/test/static/chrono_test.cpp @@ -57,43 +57,41 @@ static_assert(!QuantityPoint); // construction - same rep type static_assert( - std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); + std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); static_assert( - !std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); + std::constructible_from, sys_seconds>); static_assert( - std::constructible_from, sys_seconds>); -static_assert( - !std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(!std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(!std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert( - !std::constructible_from, sys_seconds>); -static_assert(!std::convertible_to>); + !std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(!std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(!std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(!std::constructible_from, sys_seconds>); +static_assert(!std::convertible_to>); // construction - different rep type (integral to a floating-point) -static_assert(std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::hours>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, std::chrono::seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_days>); -static_assert(std::convertible_to>); -static_assert(std::constructible_from, sys_seconds>); -static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::hours>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, std::chrono::seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_days>); +static_assert(std::convertible_to>); +static_assert(std::constructible_from, sys_seconds>); +static_assert(std::convertible_to>); static_assert(quantity{1s} == 1 * s); static_assert(quantity{1s} == 1 * s); @@ -109,13 +107,13 @@ static_assert(is_of_type>); -static_assert(std::convertible_to, std::chrono::seconds>); -static_assert(std::constructible_from>); -static_assert(std::convertible_to, std::chrono::hours>); + std::constructible_from>); +static_assert(std::convertible_to, std::chrono::seconds>); +static_assert(std::constructible_from>); +static_assert(std::convertible_to, std::chrono::hours>); static_assert( - std::constructible_from>); -static_assert(std::convertible_to, sys_seconds>); + std::constructible_from>); +static_assert(std::convertible_to, sys_seconds>); // units mapping static_assert(quantity{1ns} == 1 * ns); @@ -129,6 +127,15 @@ static_assert(quantity{std::chrono::weeks{1}} == 7 * d); static_assert(quantity{std::chrono::months{1}} == 2629746 * s); static_assert(quantity{std::chrono::years{1}} == 31556952 * s); +// conversion from chrono +static_assert(quantity{1ns} == 1 * ns); +static_assert(quantity{1s} == 1 * s); +static_assert(quantity{1ms} == 1 * ms); + +// conversion to chrono +static_assert(std::chrono::nanoseconds(quantity{1 * ns}) == 1ns); +static_assert(std::chrono::nanoseconds(quantity{1 * s}) == 1s); + // operators static_assert(quantity{1s} + 1 * s == 2 * s); static_assert(quantity{1s} + 1 * min == 61 * s); diff --git a/test/static/concepts_test.cpp b/test/static/concepts_test.cpp index 9564ed22..c67ff710 100644 --- a/test/static/concepts_test.cpp +++ b/test/static/concepts_test.cpp @@ -83,7 +83,7 @@ inline constexpr auto speed = isq::length / isq::time; static_assert(QuantitySpec); static_assert(QuantitySpec); static_assert(QuantitySpec); -static_assert(QuantitySpec)>); +static_assert(QuantitySpec)>); static_assert(QuantitySpec); static_assert(QuantitySpec(isq::length))>); static_assert(QuantitySpec); @@ -95,7 +95,7 @@ static_assert(!QuantitySpec); static_assert(detail::NamedQuantitySpec); static_assert(detail::NamedQuantitySpec); static_assert(detail::NamedQuantitySpec); -static_assert(!detail::NamedQuantitySpec)>>); +static_assert(!detail::NamedQuantitySpec)>>); static_assert(!detail::NamedQuantitySpec); static_assert(!detail::NamedQuantitySpec(isq::length))>); static_assert(detail::NamedQuantitySpec); @@ -106,7 +106,7 @@ static_assert(!detail::NamedQuantitySpec); // DerivedQuantitySpec static_assert(!detail::DerivedQuantitySpec); static_assert(!detail::DerivedQuantitySpec); -static_assert(!detail::DerivedQuantitySpec)>); +static_assert(!detail::DerivedQuantitySpec)>); static_assert(!detail::DerivedQuantitySpec); static_assert(detail::DerivedQuantitySpec); static_assert(detail::DerivedQuantitySpec(isq::length))>); @@ -118,7 +118,7 @@ static_assert(!detail::DerivedQuantitySpec); // QuantityKindSpec static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec); -static_assert(detail::QuantityKindSpec)>>); +static_assert(detail::QuantityKindSpec)>>); static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec); static_assert(!detail::QuantityKindSpec(isq::length))>); @@ -133,7 +133,7 @@ static_assert(!detail::QuantityKindSpec); // Unit static_assert(Unit); static_assert(Unit); -static_assert(Unit)>); +static_assert(Unit)>); static_assert(Unit); static_assert(Unit); static_assert(Unit); @@ -144,11 +144,11 @@ static_assert(Unit); static_assert(Unit, struct si::second>>); static_assert(Unit>>); static_assert(Unit); -static_assert(!Unit>>); +static_assert(!Unit>>); static_assert(!Unit>); static_assert(!Unit>); -static_assert(!Unit>>); -static_assert(!Unit, (si::second)>>); +static_assert(!Unit>>); +static_assert(!Unit, si::second>>); static_assert(!Unit); static_assert(!Unit); #if MP_UNITS_HOSTED @@ -159,7 +159,7 @@ static_assert(!Unit); static_assert(PrefixableUnit); static_assert(PrefixableUnit); static_assert(!PrefixableUnit); -static_assert(!PrefixableUnit)>); +static_assert(!PrefixableUnit)>); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit * si::second)>); @@ -169,11 +169,11 @@ static_assert(PrefixableUnit); static_assert(!PrefixableUnit, struct si::second>>); static_assert(!PrefixableUnit>>); static_assert(!PrefixableUnit); -static_assert(!PrefixableUnit>>); +static_assert(!PrefixableUnit>>); static_assert(!PrefixableUnit>); static_assert(!PrefixableUnit>); -static_assert(!PrefixableUnit>>); -static_assert(!PrefixableUnit, (si::second)>>); +static_assert(!PrefixableUnit>>); +static_assert(!PrefixableUnit, si::second>>); static_assert(!PrefixableUnit); static_assert(!PrefixableUnit); #if MP_UNITS_HOSTED @@ -184,7 +184,7 @@ static_assert(!PrefixableUnit); static_assert(AssociatedUnit); static_assert(!AssociatedUnit); static_assert(AssociatedUnit); -static_assert(AssociatedUnit)>); +static_assert(AssociatedUnit)>); static_assert(AssociatedUnit); static_assert(AssociatedUnit); static_assert(AssociatedUnit * si::second)>); @@ -194,11 +194,11 @@ static_assert(AssociatedUnit); static_assert(AssociatedUnit, struct si::second>>); static_assert(AssociatedUnit>>); static_assert(AssociatedUnit); -static_assert(!AssociatedUnit>>); +static_assert(!AssociatedUnit>>); static_assert(!AssociatedUnit>); static_assert(!AssociatedUnit>); -static_assert(!AssociatedUnit>>); -static_assert(!AssociatedUnit, (si::second)>>); +static_assert(!AssociatedUnit>>); +static_assert(!AssociatedUnit, si::second>>); static_assert(!AssociatedUnit); static_assert(!AssociatedUnit); #if MP_UNITS_HOSTED @@ -206,19 +206,19 @@ static_assert(!AssociatedUnit); #endif // UnitOf -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); -static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); +static_assert(UnitOf); static_assert(!UnitOf); -static_assert(!UnitOf); -static_assert(!UnitOf); +static_assert(!UnitOf); +static_assert(!UnitOf); // Reference static_assert(Reference); @@ -228,32 +228,32 @@ static_assert(Reference); static_assert(Reference); static_assert(!Reference); static_assert(!Reference); -static_assert(!Reference)>); +static_assert(!Reference)>); static_assert(!Reference); static_assert(!Reference); // ReferenceOf -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); static_assert(ReferenceOf); static_assert(ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(!ReferenceOf); -static_assert(ReferenceOf); +static_assert(ReferenceOf); static_assert(!ReferenceOf); -static_assert(ReferenceOf); -static_assert(ReferenceOf); -static_assert(!ReferenceOf); -static_assert(!ReferenceOf); +static_assert(ReferenceOf); +static_assert(ReferenceOf); +static_assert(!ReferenceOf); +static_assert(!ReferenceOf); // Representation static_assert(Representation); @@ -278,57 +278,57 @@ static_assert(!RepresentationOf); #endif // Quantity -static_assert(Quantity>); -static_assert(Quantity>); -static_assert(Quantity>); -static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); +static_assert(Quantity>); #if MP_UNITS_HOSTED static_assert(!Quantity); #endif -static_assert(!Quantity>); +static_assert(!Quantity>); static_assert(!Quantity); // QuantityOf -static_assert(QuantityOf, (isq::length)>); -static_assert(QuantityOf, (isq::radius)>); -static_assert(!QuantityOf, (isq::length)>); -static_assert(QuantityOf, (isq::length)>); -static_assert(!QuantityOf, (isq::radius)>); -static_assert(QuantityOf, (isq::length)>); -static_assert(QuantityOf, (isq::radius)>); -static_assert(!QuantityOf, (isq::dim_length)>); +static_assert(QuantityOf, isq::length>); +static_assert(QuantityOf, isq::radius>); +static_assert(!QuantityOf, isq::length>); +static_assert(QuantityOf, isq::length>); +static_assert(!QuantityOf, isq::radius>); +static_assert(QuantityOf, isq::length>); +static_assert(QuantityOf, isq::radius>); +static_assert(!QuantityOf, isq::dim_length>); static_assert(QuantityOf, dimensionless>); static_assert(QuantityOf, dimensionless>); -static_assert(QuantityOf, (isq::rotation)>); -static_assert(QuantityOf, dimensionless>); -static_assert(QuantityOf, (isq::angular_measure)>); -static_assert(!QuantityOf, dimensionless>); -static_assert(QuantityOf, (isq::angular_measure)>); -static_assert(!QuantityOf, dimensionless>); -static_assert(QuantityOf, (isq::rotation)>); -static_assert(QuantityOf, (isq::angular_measure)>); -static_assert(!QuantityOf, (isq::rotation)>); -static_assert(!QuantityOf, (isq::angular_measure)>); +static_assert(QuantityOf, isq::rotation>); +static_assert(QuantityOf, dimensionless>); +static_assert(QuantityOf, isq::angular_measure>); +static_assert(!QuantityOf, dimensionless>); +static_assert(QuantityOf, isq::angular_measure>); +static_assert(!QuantityOf, dimensionless>); +static_assert(QuantityOf, isq::rotation>); +static_assert(QuantityOf, isq::angular_measure>); +static_assert(!QuantityOf, isq::rotation>); +static_assert(!QuantityOf, isq::angular_measure>); // QuantityLike #if MP_UNITS_HOSTED static_assert(QuantityLike); static_assert(QuantityLike); #endif -static_assert(!QuantityLike>); -static_assert(!QuantityLike>); +static_assert(!QuantityLike>); +static_assert(!QuantityLike>); static_assert(!QuantityLike); // QuantityPoint -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); -static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); +static_assert(QuantityPoint>); static_assert(!QuantityPoint); -static_assert(!QuantityPoint>); +static_assert(!QuantityPoint>); static_assert(!QuantityPoint); static_assert(!QuantityPoint); #if MP_UNITS_HOSTED @@ -338,35 +338,35 @@ static_assert(!QuantityPoint> static_assert(!QuantityPoint); // QuantityPointOf -static_assert(QuantityPointOf, (isq::length)>); -static_assert(QuantityPointOf, (isq::radius)>); -static_assert(QuantityPointOf, (isq::length)>); -static_assert(!QuantityPointOf, (isq::radius)>); -static_assert(QuantityPointOf, (isq::length)>); -static_assert(QuantityPointOf, (isq::radius)>); -static_assert(QuantityPointOf, (isq::length)>); -static_assert(QuantityPointOf, (isq::radius)>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_relative_origin>); -static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, isq::length>); +static_assert(QuantityPointOf, isq::radius>); +static_assert(QuantityPointOf, isq::length>); +static_assert(!QuantityPointOf, isq::radius>); +static_assert(QuantityPointOf, isq::length>); +static_assert(QuantityPointOf, isq::radius>); +static_assert(QuantityPointOf, isq::length>); +static_assert(QuantityPointOf, isq::radius>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_relative_origin>); +static_assert(QuantityPointOf, my_origin>); // PointOrigin static_assert(PointOrigin); static_assert(PointOrigin); -static_assert(!PointOrigin>); +static_assert(!PointOrigin>); static_assert(!PointOrigin>); -static_assert(!PointOrigin>); -static_assert(!PointOrigin>); -static_assert(!PointOrigin>); +static_assert(!PointOrigin>); +static_assert(!PointOrigin>); +static_assert(!PointOrigin>); static_assert(!PointOrigin); #if MP_UNITS_HOSTED static_assert(!PointOrigin); @@ -375,38 +375,38 @@ static_assert(!PointOrigin>); static_assert(!PointOrigin); // PointOriginFor -static_assert(PointOriginFor); -static_assert(PointOriginFor); -static_assert(!PointOriginFor); -static_assert(PointOriginFor); -static_assert(PointOriginFor); -static_assert(!PointOriginFor); -static_assert(!PointOriginFor, (isq::length)>); -static_assert(!PointOriginFor, (isq::radius)>); -static_assert(!PointOriginFor, (isq::time)>); -static_assert(!PointOriginFor, (isq::length)>); -static_assert(!PointOriginFor, (isq::radius)>); -static_assert(!PointOriginFor, (isq::time)>); -static_assert(!PointOriginFor, (isq::length)>); -static_assert(!PointOriginFor, (isq::radius)>); -static_assert(!PointOriginFor, (isq::time)>); -static_assert(!PointOriginFor, (isq::length)>); -static_assert(!PointOriginFor, (isq::radius)>); -static_assert(!PointOriginFor, (isq::time)>); -static_assert(!PointOriginFor); +static_assert(PointOriginFor); +static_assert(PointOriginFor); +static_assert(!PointOriginFor); +static_assert(PointOriginFor); +static_assert(PointOriginFor); +static_assert(!PointOriginFor); +static_assert(!PointOriginFor, isq::length>); +static_assert(!PointOriginFor, isq::radius>); +static_assert(!PointOriginFor, isq::time>); +static_assert(!PointOriginFor, isq::length>); +static_assert(!PointOriginFor, isq::radius>); +static_assert(!PointOriginFor, isq::time>); +static_assert(!PointOriginFor, isq::length>); +static_assert(!PointOriginFor, isq::radius>); +static_assert(!PointOriginFor, isq::time>); +static_assert(!PointOriginFor, isq::length>); +static_assert(!PointOriginFor, isq::radius>); +static_assert(!PointOriginFor, isq::time>); +static_assert(!PointOriginFor); #if MP_UNITS_HOSTED -static_assert(!PointOriginFor); -static_assert(!PointOriginFor, (isq::length)>); +static_assert(!PointOriginFor); +static_assert(!PointOriginFor, isq::length>); #endif -static_assert(!PointOriginFor); +static_assert(!PointOriginFor); // QuantityPointLike #if MP_UNITS_HOSTED static_assert(QuantityPointLike>); static_assert(!QuantityPointLike); #endif -static_assert(!QuantityPointLike>); -static_assert(!QuantityPointLike>); +static_assert(!QuantityPointLike>); +static_assert(!QuantityPointLike>); static_assert(!QuantityPointLike); } // namespace diff --git a/test/static/custom_rep_test_min_impl.cpp b/test/static/custom_rep_test_min_impl.cpp index 8b328557..4fb2537b 100644 --- a/test/static/custom_rep_test_min_impl.cpp +++ b/test/static/custom_rep_test_min_impl.cpp @@ -78,18 +78,18 @@ static_assert(Representation>); static_assert(Representation>); // construction from a value is not allowed -static_assert(!std::constructible_from>, min_impl>); -static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert(!std::constructible_from>, min_impl>); +static_assert(!std::convertible_to, quantity>>); -static_assert(!std::constructible_from>, min_impl>); -static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert(!std::constructible_from>, min_impl>); +static_assert(!std::convertible_to, quantity>>); // multiply syntax should work template concept creates_quantity = Unit && requires { T{} * U; }; -static_assert(creates_quantity, (si::metre)>); -static_assert(creates_quantity, (si::metre)>); +static_assert(creates_quantity, si::metre>); +static_assert(creates_quantity, si::metre>); // multiply syntax static_assert(creates_quantity, one>); @@ -99,47 +99,46 @@ static_assert(creates_quantity, percent>); // construction from a quantity // min_impl -> min_impl -static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>>); +static_assert(std::convertible_to>, quantity>>); -static_assert( - std::constructible_from>, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>>); +static_assert(std::convertible_to>, quantity>>); -static_assert(std::constructible_from>, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>>); +static_assert(std::convertible_to>, quantity>>); -static_assert(!std::constructible_from>, - quantity<(si::metre), min_impl>>); // narrowing conversion -static_assert(!std::convertible_to>, quantity<(si::metre), min_impl>>); +static_assert(!std::constructible_from>, + quantity>>); // narrowing conversion +static_assert(!std::convertible_to>, quantity>>); // T -> min_impl -static_assert(std::constructible_from>, quantity<(si::metre), int>>); -static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>); +static_assert(std::convertible_to, quantity>>); -static_assert(std::constructible_from>, quantity<(si::metre), double>>); -static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>); +static_assert(std::convertible_to, quantity>>); -static_assert(std::constructible_from>, quantity<(si::metre), int>>); -static_assert(std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert(std::constructible_from>, quantity>); +static_assert(std::convertible_to, quantity>>); -static_assert(!std::constructible_from>, - quantity<(si::metre), double>>); // narrowing conversion -static_assert(!std::convertible_to, quantity<(si::metre), min_impl>>); +static_assert( + !std::constructible_from>, quantity>); // narrowing conversion +static_assert(!std::convertible_to, quantity>>); // min_impl -> T -static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), int>>); +static_assert(std::constructible_from, quantity>>); +static_assert(std::convertible_to>, quantity>); -static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), double>>); +static_assert(std::constructible_from, quantity>>); +static_assert(std::convertible_to>, quantity>); -static_assert(std::constructible_from, quantity<(si::metre), min_impl>>); -static_assert(std::convertible_to>, quantity<(si::metre), double>>); +static_assert(std::constructible_from, quantity>>); +static_assert(std::convertible_to>, quantity>); -static_assert(!std::constructible_from, - quantity<(si::metre), min_impl>>); // narrowing conversion -static_assert(!std::convertible_to>, quantity<(si::metre), int>>); +static_assert( + !std::constructible_from, quantity>>); // narrowing conversion +static_assert(!std::convertible_to>, quantity>); // arithmetic operators diff --git a/test/static/dimension_test.cpp b/test/static/dimension_test.cpp index f1d64590..8064831e 100644 --- a/test/static/dimension_test.cpp +++ b/test/static/dimension_test.cpp @@ -33,7 +33,7 @@ namespace { using namespace mp_units; -using dimension_one_ = struct mp_units::dimension_one; +using dimension_one_ = struct dimension_one; // clang-format off inline constexpr struct length_ final : base_dimension<"L"> {} length; diff --git a/test/static/quantity_point_test.cpp b/test/static/quantity_point_test.cpp index 50dfb67e..f04e9c1a 100644 --- a/test/static/quantity_point_test.cpp +++ b/test/static/quantity_point_test.cpp @@ -58,24 +58,24 @@ inline constexpr struct mean_sea_level final : absolute_point_origin { +inline constexpr struct same_mean_sea_level final : relative_point_origin { } same_mean_sea_level; -inline constexpr struct ground_level final : relative_point_origin { +inline constexpr struct ground_level final : relative_point_origin { } ground_level; inline constexpr auto my_ground_level = ground_level; -inline constexpr struct same_ground_level1 final : relative_point_origin { +inline constexpr struct same_ground_level1 final : relative_point_origin { } same_ground_level1; -inline constexpr struct same_ground_level2 final : relative_point_origin { +inline constexpr struct same_ground_level2 final : relative_point_origin { } same_ground_level2; -inline constexpr struct tower_peak final : relative_point_origin { +inline constexpr struct tower_peak final : relative_point_origin { } tower_peak; -inline constexpr struct other_ground_level final : relative_point_origin { +inline constexpr struct other_ground_level final : relative_point_origin { } other_ground_level; inline constexpr struct other_absolute_level final : absolute_point_origin { @@ -152,10 +152,10 @@ static_assert(zeroth_point_origin != zeroth_point_origin) == sizeof(double)); -static_assert(sizeof(quantity_point<(isq::height[m]), mean_sea_level>) == sizeof(double)); -static_assert(sizeof(quantity_point<(si::metre), ground_level, short>) == sizeof(short)); -static_assert(sizeof(quantity_point<(isq::height[m]), ground_level, short>) == sizeof(short)); +static_assert(sizeof(quantity_point) == sizeof(double)); +static_assert(sizeof(quantity_point) == sizeof(double)); +static_assert(sizeof(quantity_point) == sizeof(short)); +static_assert(sizeof(quantity_point) == sizeof(short)); template typename QP> concept invalid_types = requires { @@ -188,15 +188,15 @@ static_assert(invalid_types); template typename QP> concept valid_types = requires { - typename QP<(si::metre), mean_sea_level, int>; - typename QP<(isq::height[m]), mean_sea_level, int>; - typename QP<(special_height[m]), mean_sea_level, int>; - typename QP<(si::metre), ground_level, int>; - typename QP<(isq::height[m]), ground_level, int>; - typename QP<(special_height[m]), ground_level, int>; - typename QP<(isq::height[m]), zeroth_point_origin<(isq::length)>, int>; - typename QP<(isq::height[m]), zeroth_point_origin>, int>; - typename QP<(si::metre), zeroth_point_origin<(isq::height)>, int>; + typename QP; + typename QP; + typename QP; + typename QP; + typename QP; + typename QP; + typename QP, int>; + typename QP>, int>; + typename QP, int>; }; static_assert(valid_types); @@ -217,14 +217,14 @@ static_assert(std::is_nothrow_destructible_v>); static_assert(std::is_standard_layout_v>); -static_assert(std::default_initializable>); -static_assert(std::move_constructible>); -static_assert(std::copy_constructible>); -static_assert(std::equality_comparable>); -static_assert(std::totally_ordered>); -static_assert(std::regular>); +static_assert(std::default_initializable>); +static_assert(std::move_constructible>); +static_assert(std::copy_constructible>); +static_assert(std::equality_comparable>); +static_assert(std::totally_ordered>); +static_assert(std::regular>); -static_assert(std::three_way_comparable>); +static_assert(std::three_way_comparable>); ////////////////// @@ -235,53 +235,51 @@ static_assert(quantity_point::reference == si::metre); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, zeroth_point_origin_>>); -static_assert( - is_of_type::absolute_point_origin, zeroth_point_origin_>>); +static_assert(is_of_type::point_origin, zeroth_point_origin_>>); +static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, zeroth_point_origin_>); -static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>); +static_assert(is_of_type::point_origin, zeroth_point_origin_>); +static_assert(is_of_type::absolute_point_origin, zeroth_point_origin_>); static_assert(quantity_point::reference == si::metre); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct mean_sea_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct mean_sea_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct mean_sea_level>); -static_assert( - is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct mean_sea_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct ground_level>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct ground_level>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == isq::height[m]); static_assert(quantity_point::quantity_spec == isq::height); static_assert(quantity_point::dimension == isq::dim_length); static_assert(quantity_point::unit == si::metre); -static_assert(is_of_type::point_origin, struct tower_peak>); -static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); +static_assert(is_of_type::point_origin, struct tower_peak>); +static_assert(is_of_type::absolute_point_origin, struct mean_sea_level>); static_assert(quantity_point::reference == si::kelvin); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, struct si::absolute_zero>); +static_assert(is_of_type::point_origin, struct si::absolute_zero>); static_assert( - is_of_type::absolute_point_origin, struct si::absolute_zero>); + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == isq::thermodynamic_temperature[si::kelvin]); @@ -290,11 +288,10 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); +static_assert(is_of_type::point_origin, + struct si::absolute_zero>); static_assert( - is_of_type::point_origin, - struct si::absolute_zero>); -static_assert( - is_of_type::absolute_point_origin, + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == @@ -304,20 +301,19 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::kelvin); -static_assert(is_of_type::point_origin, +static_assert(is_of_type::point_origin, + struct si::absolute_zero>); +static_assert(is_of_type::absolute_point_origin, struct si::absolute_zero>); -static_assert( - is_of_type::absolute_point_origin, - struct si::absolute_zero>); static_assert(quantity_point::reference == si::degree_Celsius); static_assert(quantity_point::quantity_spec == kind_of); static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::degree_Celsius); -static_assert(is_of_type::point_origin, struct si::ice_point>); +static_assert(is_of_type::point_origin, struct si::ice_point>); static_assert( - is_of_type::absolute_point_origin, struct si::absolute_zero>); + is_of_type::absolute_point_origin, struct si::absolute_zero>); static_assert(quantity_point::reference == isq::Celsius_temperature[si::degree_Celsius]); @@ -326,10 +322,10 @@ static_assert(quantity_point::dimension == isq::dim_thermodynamic_temperature); static_assert(quantity_point::unit == si::degree_Celsius); -static_assert(is_of_type::point_origin, +static_assert(is_of_type::point_origin, struct si::ice_point>); static_assert( - is_of_type::absolute_point_origin, + is_of_type::absolute_point_origin, struct si::absolute_zero>); @@ -337,18 +333,18 @@ static_assert( // member types ////////////////// -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, int>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, int>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::quantity_type, quantity>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::quantity_type, quantity>); -static_assert(is_same_v::rep, int>); +static_assert(is_same_v::rep, int>); static_assert( - is_same_v::quantity_type, quantity>); + is_same_v::quantity_type, quantity>); //////////////////////////// @@ -375,11 +371,11 @@ static_assert( ////////////////////////////// // there is no construction from a value -static_assert(!std::constructible_from, double>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, double>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, int>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, int>); +static_assert(!std::convertible_to>); static_assert(!std::constructible_from, double>); static_assert(!std::convertible_to>); @@ -400,135 +396,135 @@ static_assert(!std::convertible_to, quantity<(si::metre)>>); -static_assert(!std::convertible_to, quantity_point<(si::metre)>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(si::metre)>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(si::metre)>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(isq::speed[m / s])>>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(isq::speed[m / s])>>); -static_assert(!std::convertible_to, quantity_point<(isq::length[m] / isq::time[s])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(isq::length[m] / isq::time[s])>>); -static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point<(isq::speed[m / s])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); static_assert(std::constructible_from, quantity>); static_assert(!std::convertible_to, quantity_point>); // different dimensions -static_assert(!std::constructible_from, quantity<(si::second)>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // convertible but different quantity_specs -static_assert(std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::length[m])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity<(special_height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::width[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::width[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity<(isq::length[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); #if MP_UNITS_HOSTED // quantity-like -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, std::chrono::seconds>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, std::chrono::seconds>); +static_assert(!std::convertible_to>); #endif // ---------------------- // explicit point origins // ---------------------- -static_assert(!std::constructible_from, quantity<(si::metre)>>); -static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(si::metre)>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); static_assert(!std::constructible_from, quantity>); static_assert(!std::convertible_to, quantity_point>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::width[m]), zeroth_length>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::width[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), zeroth_length>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // different dimensions -static_assert(!std::constructible_from, quantity<(si::second)>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity<(isq::length[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); // not-compatible origin -static_assert(!std::constructible_from, quantity<(isq::length[m])>>); -static_assert(!std::convertible_to, quantity_point<((si::metre)), mean_sea_level>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity_point>); #if MP_UNITS_HOSTED // quantity-like -static_assert(!std::constructible_from>, +static_assert(!std::constructible_from>, std::chrono::seconds>); static_assert(!std::convertible_to>>); + quantity_point>>); -static_assert(!std::constructible_from>, +static_assert(!std::constructible_from>, std::chrono::seconds>); static_assert(!std::convertible_to>>); + quantity_point>>); static_assert( - !std::constructible_from>, + !std::constructible_from>, std::chrono::seconds>); static_assert( !std::convertible_to>>); + quantity_point>>); #endif @@ -537,146 +533,140 @@ static_assert( /////////////////////////////////////// // implicit origin -static_assert(std::constructible_from, quantity_point<(si::metre)>>); -static_assert(std::convertible_to, quantity_point<(si::metre)>>); -static_assert(std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(std::convertible_to, quantity_point<(si::metre)>>); -static_assert(std::constructible_from, quantity_point<(si::metre)>>); -static_assert(std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(isq::speed[m / s])>>); -static_assert( - std::convertible_to, quantity_point<(isq::length[m]) / isq::time[s]>>); + std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point<(isq::speed[m / s])>>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); -static_assert(std::constructible_from, quantity_point<(isq::length[m]) / isq::time[s]>>); -static_assert(std::convertible_to, quantity_point>); +static_assert(std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); // convertible but different quantity_specs -static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::length[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::width[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point<(isq::width[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // non-convertible quantity_specs -static_assert(!std::constructible_from, quantity_point<(isq::length[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // mixed origins -static_assert(!std::constructible_from, quantity_point<(si::metre)>>); -static_assert(!std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); -static_assert( - !std::constructible_from, quantity_point<(isq::height[m])>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); -static_assert(!std::convertible_to, quantity_point<(si::metre)>>); -static_assert( - !std::constructible_from, quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::convertible_to, quantity_point<(isq::height[m])>>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); +static_assert(!std::constructible_from, quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // same explicit origins static_assert( - std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); + std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[km]), mean_sea_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[km]), mean_sea_level>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point>); static_assert( - std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, - quantity_point<(si::metre), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point>); static_assert( - std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, +static_assert(std::constructible_from, + quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert( + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert( + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert(std::constructible_from, quantity_point>); static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); + quantity_point>); static_assert( - std::constructible_from, quantity_point<(si::metre), ground_level>>); -static_assert( - std::convertible_to, quantity_point<(si::metre), ground_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), ground_level>>); -static_assert( - std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[km]), mean_sea_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[km]), ground_level>>); -static_assert( - std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); + std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(isq::height[m]), ground_level>>); + std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point<(si::metre), ground_level>>); + std::convertible_to, quantity_point>); + +static_assert(std::constructible_from, + quantity_point>); +static_assert( + std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(si::metre), ground_level>>); + std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, +static_assert( + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert( + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert(std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point<(isq::height[m]), ground_level>>); + std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(si::metre), ground_level>>); -static_assert( - std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); + std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(si::metre), mean_sea_level>>); -static_assert( - std::convertible_to, quantity_point<(si::metre), ground_level>>); + std::constructible_from, quantity_point>); +static_assert(std::convertible_to, quantity_point>); static_assert( - std::constructible_from, quantity_point<(si::metre), other_ground_level>>); + std::constructible_from, quantity_point>); static_assert( - std::convertible_to, quantity_point<(si::metre), ground_level>>); + std::convertible_to, quantity_point>); static_assert( std::constructible_from, quantity_point>); @@ -692,121 +682,121 @@ static_assert( static_assert( std::convertible_to, quantity_point>); -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), zeroth_length>>); -static_assert(std::convertible_to, - quantity_point<(isq::length[m]), zeroth_length>>); +static_assert(std::constructible_from, + quantity_point>); +static_assert( + std::convertible_to, quantity_point>); // quantity_specs with common_quantity_spec -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), zeroth_length>>); -static_assert(!std::convertible_to, - quantity_point<(isq::width[m]), zeroth_length>>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert( + !std::convertible_to, quantity_point>); -static_assert(!std::constructible_from, - quantity_point<(isq::width[m]), zeroth_length>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), zeroth_length>>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert( + !std::convertible_to, quantity_point>); // different dimensions -static_assert(!std::constructible_from, - quantity_point<(si::kelvin), (si::ice_point)>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert( + !std::constructible_from, quantity_point>); +static_assert( + !std::convertible_to, quantity_point>); // non-convertible quantity_specs static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::convertible_to, + quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // implicit conversion from another quantity point only if non-truncating // int -> double OK -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level, int>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point>); +static_assert(std::convertible_to, + quantity_point>); // truncating double -> int not allowed -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level, int>>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert(!std::convertible_to, + quantity_point>); // kilometre -> metre OK -static_assert(std::constructible_from, - quantity_point<(isq::height[km]), mean_sea_level, int>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level, int>>); +static_assert(std::constructible_from, + quantity_point>); +static_assert(std::convertible_to, + quantity_point>); // truncating metre -> kilometre not allowed -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level, int>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[km]), mean_sea_level, int>>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert(!std::convertible_to, + quantity_point>); // converting to double always OK -static_assert(std::constructible_from, - quantity_point<(isq::height[km]), mean_sea_level, int>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level, int>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[km]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point>); +static_assert(std::convertible_to, + quantity_point>); +static_assert(std::constructible_from, + quantity_point>); +static_assert(std::convertible_to, + quantity_point>); // same but not a default origin -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); - -static_assert(std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); +static_assert(std::constructible_from, + quantity_point>); static_assert( - std::convertible_to, quantity_point<(si::metre), mean_sea_level>>); + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, - quantity_point<(si::metre), mean_sea_level>>); static_assert( - std::convertible_to, quantity_point<(isq::height[m]), mean_sea_level>>); + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); -static_assert(std::constructible_from, +static_assert( + std::constructible_from, quantity_point>); +static_assert( + std::convertible_to, quantity_point>); + +static_assert(std::constructible_from, quantity_point>); static_assert(std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); + quantity_point>); static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::convertible_to, + quantity_point>); +static_assert(!std::convertible_to, quantity_point>); // different origins -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), other_absolute_level>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), mean_sea_level>>); -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), other_absolute_level>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), ground_level>>); -static_assert(!std::constructible_from, - quantity_point<(isq::height[m]), ground_level>>); -static_assert(!std::convertible_to, - quantity_point<(isq::height[m]), other_absolute_level>>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert(!std::convertible_to, + quantity_point>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert(!std::convertible_to, + quantity_point>); +static_assert(!std::constructible_from, + quantity_point>); +static_assert(!std::convertible_to, + quantity_point>); #if MP_UNITS_HOSTED // quantity-point-like static_assert( - std::constructible_from>, sys_seconds>); + std::constructible_from>, sys_seconds>); static_assert( - std::convertible_to>>); + std::convertible_to>>); // incompatible origin -static_assert(!std::constructible_from>, - sys_seconds>); static_assert( - !std::convertible_to>>); + !std::constructible_from>, sys_seconds>); +static_assert( + !std::convertible_to>>); #endif @@ -835,19 +825,17 @@ static_assert((mean_sea_level + 42 * m).quantity_from(mean_sea_level) == 42 * m) static_assert((ground_level + 42 * m).quantity_from(ground_level) == 42 * m); static_assert((tower_peak + 42 * m).quantity_from(tower_peak) == 42 * m); -static_assert(quantity_point<(isq::height[m]), mean_sea_level>(ground_level + 42 * m).quantity_from(mean_sea_level) == +static_assert(quantity_point(ground_level + 42 * m).quantity_from(mean_sea_level) == 84 * m); -static_assert(quantity_point<(isq::height[m]), mean_sea_level>(tower_peak + 42 * m).quantity_from(mean_sea_level) == +static_assert(quantity_point(tower_peak + 42 * m).quantity_from(mean_sea_level) == 126 * m); -static_assert(quantity_point<(isq::height[m]), ground_level>(mean_sea_level + 84 * m).quantity_from(ground_level) == +static_assert(quantity_point(mean_sea_level + 84 * m).quantity_from(ground_level) == 42 * m); -static_assert(quantity_point<(isq::height[m]), ground_level>(tower_peak + 42 * m).quantity_from(ground_level) == - 84 * m); +static_assert(quantity_point(tower_peak + 42 * m).quantity_from(ground_level) == 84 * m); -static_assert(quantity_point<(isq::height[m]), tower_peak>(mean_sea_level + 42 * m).quantity_from(tower_peak) == - -42 * m); -static_assert(quantity_point<(isq::height[m]), tower_peak>(ground_level + 84 * m).quantity_from(tower_peak) == 42 * m); +static_assert(quantity_point(mean_sea_level + 42 * m).quantity_from(tower_peak) == -42 * m); +static_assert(quantity_point(ground_level + 84 * m).quantity_from(tower_peak) == 42 * m); static_assert((mean_sea_level + 42 * m).point_for(mean_sea_level).quantity_from(mean_sea_level) == 42 * m); static_assert((ground_level + 42 * m).point_for(mean_sea_level).quantity_from(mean_sea_level) == 84 * m); @@ -862,7 +850,7 @@ static_assert((mean_sea_level + 42 * m).point_for(tower_peak).quantity_from(towe static_assert((ground_level + 84 * m).point_for(tower_peak).quantity_from(tower_peak) == 42 * m); static_assert(is_of_type<(ground_level + isq::height(short{42} * m)).point_for(mean_sea_level), - quantity_point<(isq::height[m]), mean_sea_level, int>>); + quantity_point>); /////////////////////////////////// @@ -889,8 +877,8 @@ static_assert(is_of_type<(mean_sea_level + 2500. * m).force_in(km), quantit template typename QP> concept invalid_unit_conversion = requires { - requires !requires { QP<(isq::height[m]), mean_sea_level, int>(2000 * m).in(km); }; // truncating conversion - requires !requires { QP<(isq::height[m]), mean_sea_level, int>(2 * m).in(s); }; // invalid unit + requires !requires { QP(2000 * m).in(km); }; // truncating conversion + requires !requires { QP(2 * m).in(s); }; // invalid unit }; static_assert(invalid_unit_conversion); @@ -938,12 +926,13 @@ static_assert(quantity_point{sys_seconds{24h}}.quantity_spec == kind_of typename QP> concept invalid_compound_assignments = requires() { // truncating not allowed - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += 2.5 * m; }; - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= 2.5 * m; }; - requires !requires(QP l) { l += 2 * (isq::height[m]); }; - requires !requires(QP l) { l -= 2 * (isq::height[m]); }; + requires !requires(QP l) { l += 2.5 * m; }; + requires !requires(QP l) { l -= 2.5 * m; }; + requires !requires(QP l) { l += 2 * isq::height[m]; }; + requires !requires(QP l) { l -= 2 * isq::height[m]; }; // only quantities can be added or subtracted - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += 2; }; - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= 2; }; + requires !requires(QP l) { l += 2; }; + requires !requires(QP l) { l -= 2; }; // no unit constants - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l += m; }; - requires !requires(QP<(isq::height[m]), mean_sea_level, int> l) { l -= m; }; + requires !requires(QP l) { l += m; }; + requires !requires(QP l) { l -= m; }; }; static_assert(invalid_compound_assignments); @@ -1143,12 +1132,12 @@ concept invalid_binary_operations = requires { requires !requires { Origin - Origin; }; // unit constants - requires !requires { QP<(si::metre), mean_sea_level, int>(1) + m; }; - requires !requires { QP<(si::metre), mean_sea_level, int>(1) - m; }; + requires !requires { QP(1) + m; }; + requires !requires { QP(1) - m; }; requires !requires { Origin + m; }; requires !requires { Origin - m; }; - requires !requires { m + QP<(si::metre), mean_sea_level, int>(1); }; - requires !requires { m - QP<(si::metre), mean_sea_level, int>(1); }; + requires !requires { m + QP(1); }; + requires !requires { m - QP(1); }; requires !requires { m + Origin; }; requires !requires { m - Origin; }; }; @@ -1185,36 +1174,36 @@ static_assert(is_of_type<1 * m + (mean_sea_level + 1 * km), quantity_point>); static_assert( - is_of_type<1 * m + (mean_sea_level + isq::height(1 * m)), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<1 * m + (mean_sea_level + isq::height(1 * m)), quantity_point>); static_assert( - is_of_type<1 * m + (mean_sea_level + isq::height(1 * km)), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<1 * m + (mean_sea_level + isq::height(1 * km)), quantity_point>); static_assert( - is_of_type<1 * km + (mean_sea_level + isq::height(1 * m)), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<1 * km + (mean_sea_level + isq::height(1 * m)), quantity_point>); static_assert( - is_of_type>); + is_of_type>); static_assert( - is_of_type>); + is_of_type>); static_assert( - is_of_type>); + is_of_type>); static_assert(is_of_type>); + quantity_point>); static_assert(is_of_type>); + quantity_point>); static_assert(is_of_type>); + quantity_point>); static_assert(is_of_type>); static_assert(is_of_type, mean_sea_level, int>>); -static_assert(is_of_type>); +static_assert(is_of_type>); static_assert( is_of_type>); static_assert(is_of_type], mean_sea_level, int>>); static_assert(is_of_type<1 * m + mean_sea_level, quantity_point>); static_assert(is_of_type<1 * km + mean_sea_level, quantity_point, mean_sea_level, int>>); -static_assert(is_of_type>); +static_assert(is_of_type>); static_assert( is_of_type>); static_assert(is_of_type>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * m), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * m), quantity_point>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * km), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + 1 * m) - isq::height(1 * km), quantity_point>); static_assert( - is_of_type<(mean_sea_level + 1 * km) - isq::height(1 * m), quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + 1 * km) - isq::height(1 * m), quantity_point>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * m, quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * m, quantity_point>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * km, quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - 1 * km, quantity_point>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * km)) - 1 * m, quantity_point<(isq::height[m]), mean_sea_level, int>>); + is_of_type<(mean_sea_level + isq::height(1 * km)) - 1 * m, quantity_point>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - isq::height(1 * m), - quantity_point<(isq::height[m]), mean_sea_level, int>>); + quantity_point>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - isq::height(1 * km), - quantity_point<(isq::height[m]), mean_sea_level, int>>); + quantity_point>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * km)) - isq::height(1 * m), - quantity_point<(isq::height[m]), mean_sea_level, int>>); + quantity_point>); static_assert(is_of_type>); static_assert(is_of_type, mean_sea_level, int>>); @@ -1265,39 +1254,39 @@ static_assert(is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + 1 * m), q static_assert(is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + 1 * km), quantity>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * m)), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * m)), quantity>); static_assert( - is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * km)), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + isq::height(1 * km)), quantity>); static_assert( - is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + isq::height(1 * m)), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + 1 * km) - (mean_sea_level + isq::height(1 * m)), quantity>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * m), quantity>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * km), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + 1 * km), quantity>); static_assert( - is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); + is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + 1 * m), quantity>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + isq::height(1 * m)), - quantity<(isq::height[m]), int>>); + quantity>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * m)) - (mean_sea_level + isq::height(1 * km)), - quantity<(isq::height[m]), int>>); + quantity>); static_assert(is_of_type<(mean_sea_level + isq::height(1 * km)) - (mean_sea_level + isq::height(1 * m)), - quantity<(isq::height[m]), int>>); + quantity>); static_assert(is_of_type<(mean_sea_level + 1 * m) - (mean_sea_level + 1 * m), quantity>); static_assert(is_of_type<(ground_level + 1 * m) - (ground_level + 1 * m), quantity>); static_assert(is_of_type<(tower_peak + 1 * m) - (tower_peak + 1 * m), quantity>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(ground_level + 1 * m) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(tower_peak + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(ground_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(tower_peak + 1 * m) - (mean_sea_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(other_ground_level + 1 * m) - (ground_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(ground_level + 1 * m) - (other_ground_level + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(other_ground_level + 1 * m) - (tower_peak + 1 * m), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(tower_peak + 1 * m) - (other_ground_level + 1 * m), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - (ground_level + 1 * m), quantity>); +static_assert(is_of_type<(ground_level + 1 * m) - (mean_sea_level + 1 * m), quantity>); +static_assert(is_of_type<(tower_peak + 1 * m) - (ground_level + 1 * m), quantity>); +static_assert(is_of_type<(ground_level + 1 * m) - (tower_peak + 1 * m), quantity>); +static_assert(is_of_type<(tower_peak + 1 * m) - (mean_sea_level + 1 * m), quantity>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - (tower_peak + 1 * m), quantity>); +static_assert(is_of_type<(other_ground_level + 1 * m) - (ground_level + 1 * m), quantity>); +static_assert(is_of_type<(ground_level + 1 * m) - (other_ground_level + 1 * m), quantity>); +static_assert(is_of_type<(other_ground_level + 1 * m) - (tower_peak + 1 * m), quantity>); +static_assert(is_of_type<(tower_peak + 1 * m) - (other_ground_level + 1 * m), quantity>); static_assert(is_of_type>); static_assert(is_of_type, int>>); @@ -1309,32 +1298,32 @@ static_assert(is_of_type>); static_assert(is_of_type<(ground_level + 1 * km) - ground_level, quantity, int>>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type<(ground_level + 1 * m) - mean_sea_level, quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(ground_level + 1 * km) - mean_sea_level, quantity<(isq::height[m]), int>>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type<(ground_level + 1 * m) - mean_sea_level, quantity>); +static_assert(is_of_type<(ground_level + 1 * km) - mean_sea_level, quantity>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type<(mean_sea_level + 1 * m) - ground_level, quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(mean_sea_level + 1 * km) - ground_level, quantity<(isq::height[m]), int>>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type<(mean_sea_level + 1 * m) - ground_level, quantity>); +static_assert(is_of_type<(mean_sea_level + 1 * km) - ground_level, quantity>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); -static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); +static_assert(is_of_type>); -static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + mean_sea_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + mean_sea_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + ground_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + ground_level) - (1 * m + other_ground_level), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + tower_peak), quantity<(isq::height[m]), int>>); -static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + other_ground_level), quantity<(isq::height[m]), int>>); +static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + ground_level), quantity>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + mean_sea_level), quantity>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + ground_level), quantity>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + tower_peak), quantity>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + mean_sea_level), quantity>); +static_assert(is_of_type<(1 * m + mean_sea_level) - (1 * m + tower_peak), quantity>); +static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + ground_level), quantity>); +static_assert(is_of_type<(1 * m + ground_level) - (1 * m + other_ground_level), quantity>); +static_assert(is_of_type<(1 * m + other_ground_level) - (1 * m + tower_peak), quantity>); +static_assert(is_of_type<(1 * m + tower_peak) - (1 * m + other_ground_level), quantity>); // check for integral types promotion @@ -1654,8 +1643,8 @@ static_assert(is_of_type<(zero_Hz + 5 * isq::frequency[Hz]) - (zero_Hz + 10 / (2 static_assert((quantity_point{10 / (2 * isq::period_duration[s])} + 5 * isq::frequency[Hz]).quantity_from_zero() == 10 * isq::frequency[Hz]); -static_assert((10 / (2 * isq::period_duration[s]) + (zero_Hz + 5 * isq::frequency[Hz])).quantity_from_zero() == - 10 * isq::frequency[Hz]); +static_assert((10 / (2 * isq::period_duration[s]) + quantity_point{zero_Hz + 5 * isq::frequency[Hz]}) + .quantity_from_zero() == 10 * isq::frequency[Hz]); static_assert((quantity_point{5 * isq::frequency[Hz]} + 10 / (2 * isq::period_duration[s])).quantity_from_zero() == 10 * isq::frequency[Hz]); static_assert((5 * isq::frequency[Hz] + quantity_point{10 / (2 * isq::period_duration[s])}).quantity_from_zero() == @@ -1729,7 +1718,7 @@ static_assert(value_cast(quantity_point{2 * km}).quantity_from_zero().numeric static_assert(value_cast(quantity_point{2000 * m}).quantity_from_zero().numerical_value_in(km) == 2); static_assert(value_cast(quantity_point{1.23 * m}).quantity_from_zero().numerical_value_in(m) == 1); static_assert( - value_cast<(km / h)>(quantity_point{2000.0 * m / (3600.0 * s)}).quantity_from_zero().numerical_value_in(km / h) == 2); + value_cast(quantity_point{2000.0 * m / (3600.0 * s)}).quantity_from_zero().numerical_value_in(km / h) == 2); // lvalue references in value_cast namespace lvalue_tests { constexpr quantity_point lvalue_qp{2 * km}; diff --git a/test/static/quantity_spec_test.cpp b/test/static/quantity_spec_test.cpp index ed4cb359..ee4e86a8 100644 --- a/test/static/quantity_spec_test.cpp +++ b/test/static/quantity_spec_test.cpp @@ -33,8 +33,8 @@ namespace { using namespace mp_units; -using dimensionless_ = struct mp_units::dimensionless; -using dim_one_ = struct mp_units::dimension_one; +using dimensionless_ = struct dimensionless; +using dim_one_ = struct dimension_one; // clang-format off inline constexpr struct dim_length_ final : base_dimension<"L"> {} dim_length; diff --git a/test/static/quantity_test.cpp b/test/static/quantity_test.cpp index 44ee65ad..89f169bb 100644 --- a/test/static/quantity_test.cpp +++ b/test/static/quantity_test.cpp @@ -84,14 +84,14 @@ static_assert(std::is_nothrow_destructible_v>); static_assert(std::is_trivially_copyable_v>); static_assert(std::is_standard_layout_v>); -static_assert(std::default_initializable>); -static_assert(std::move_constructible>); -static_assert(std::copy_constructible>); -static_assert(std::equality_comparable>); -static_assert(std::totally_ordered>); -static_assert(std::regular>); +static_assert(std::default_initializable>); +static_assert(std::move_constructible>); +static_assert(std::copy_constructible>); +static_assert(std::equality_comparable>); +static_assert(std::totally_ordered>); +static_assert(std::regular>); -static_assert(std::three_way_comparable>); +static_assert(std::three_way_comparable>); ////////////////// @@ -112,8 +112,8 @@ static_assert(quantity::unit == si::metre); // member types ///////////////// -static_assert(is_same_v::rep, double>); -static_assert(is_same_v::rep, int>); +static_assert(is_same_v::rep, double>); +static_assert(is_same_v::rep, int>); [[maybe_unused]] volatile std::int16_t vint = 123; static_assert(is_same_v); @@ -139,11 +139,11 @@ static_assert(quantity::max().numerical_value_in(m) == s ///////////////////////////////////////////////// // construction from a value is private -static_assert(!std::constructible_from, double>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, double>); +static_assert(!std::convertible_to>); -static_assert(!std::constructible_from, int>); -static_assert(!std::convertible_to>); +static_assert(!std::constructible_from, int>); +static_assert(!std::convertible_to>); static_assert(std::constructible_from, double>); static_assert(std::convertible_to>); @@ -163,46 +163,45 @@ static_assert(std::convertible_to>); /////////////////////////////////////// // conversion only between convertible quantities -static_assert(std::constructible_from, quantity<(isq::length[m])>>); -static_assert(std::convertible_to, quantity<(isq::length[m])>>); -static_assert(std::constructible_from, quantity<(isq::distance[m])>>); -static_assert(std::convertible_to, quantity<(isq::length[m])>>); -static_assert(std::constructible_from, quantity<(isq::length[km])>>); -static_assert(std::convertible_to, quantity<(isq::length[m])>>); +static_assert(std::constructible_from, quantity>); +static_assert(std::convertible_to, quantity>); +static_assert(std::constructible_from, quantity>); +static_assert(std::convertible_to, quantity>); +static_assert(std::constructible_from, quantity>); +static_assert(std::convertible_to, quantity>); // conversion between different quantities not allowed -static_assert(!std::constructible_from, quantity<(isq::time[s])>>); -static_assert(!std::convertible_to, quantity<(isq::length[m])>>); -static_assert(!std::constructible_from, quantity<(isq::speed[m / s])>>); -static_assert(!std::convertible_to, quantity<(isq::length[m])>>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity>); +static_assert(!std::constructible_from, quantity>); +static_assert(!std::convertible_to, quantity>); // implicit conversion from another quantity only if non-truncating +static_assert(std::constructible_from, quantity>); // int -> double OK +static_assert(std::convertible_to, quantity>); // int -> double OK + +static_assert(!std::constructible_from, + quantity>); // truncating double -> int not allowed +static_assert(!std::convertible_to, + quantity>); // truncating double -> int not allowed + +static_assert(std::constructible_from, + quantity>); // kilometre -> metre OK +static_assert(std::convertible_to, + quantity>); // kilometre -> metre OK + +static_assert(!std::constructible_from, + quantity>); // truncating metre -> + // kilometre not allowed static_assert( - std::constructible_from, quantity<(isq::length[m]), int>>); // int -> double OK -static_assert(std::convertible_to, quantity<(isq::length[m])>>); // int -> double OK - -static_assert(!std::constructible_from, - quantity<(isq::length[m])>>); // truncating double -> int not allowed -static_assert(!std::convertible_to, - quantity<(isq::length[m]), int>>); // truncating double -> int not allowed - -static_assert(std::constructible_from, - quantity<(isq::length[km]), int>>); // kilometre -> metre OK -static_assert(std::convertible_to, - quantity<(isq::length[m]), int>>); // kilometre -> metre OK - -static_assert(!std::constructible_from, - quantity<(isq::length[m]), int>>); // truncating metre -> - // kilometre not allowed -static_assert( - !std::convertible_to, - quantity<(isq::length[km]), int>>); // truncating metre -> kilometre not allowed + !std::convertible_to, + quantity>); // truncating metre -> kilometre not allowed // converting to double always OK -static_assert(std::constructible_from, quantity<(isq::length[km]), int>>); -static_assert(std::convertible_to, quantity<(isq::length[m])>>); -static_assert(std::constructible_from, quantity<(isq::length[m]), int>>); -static_assert(std::convertible_to, quantity<(isq::length[km])>>); +static_assert(std::constructible_from, quantity>); +static_assert(std::convertible_to, quantity>); +static_assert(std::constructible_from, quantity>); +static_assert(std::convertible_to, quantity>); /////////////////////// // obtaining a number @@ -220,16 +219,16 @@ static_assert(quantity(1500 * m).numerical_value_in(km) == 1.5) static_assert(!std::convertible_to, double>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, double>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, double>); +static_assert(std::constructible_from>); static_assert(!std::convertible_to, int>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, int>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, int>); +static_assert(std::constructible_from>); static_assert(!std::convertible_to, double>); static_assert(std::constructible_from>); -static_assert(!std::convertible_to, double>); -static_assert(std::constructible_from>); +static_assert(!std::convertible_to, double>); +static_assert(std::constructible_from>); /////////////////////////////////// @@ -319,9 +318,9 @@ struct derived_quantity : quantity { R::operator=(t); return *this; } - constexpr derived_quantity& operator=(R&& other) + constexpr derived_quantity& operator=(R&& t) { - R::operator=(std::move(other)); + R::operator=(std::move(t)); return *this; } // NOLINTBEGIN(google-explicit-constructor, hicpp-explicit-conversions) @@ -332,9 +331,9 @@ struct derived_quantity : quantity { // NOLINTEND(google-explicit-constructor, hicpp-explicit-conversions) }; -static_assert(Quantity, "NTTP type description">>); +static_assert(Quantity, "NTTP type description">>); -constexpr QuantityOf<(isq::length)> auto get_length_derived_quantity() noexcept +constexpr QuantityOf auto get_length_derived_quantity() noexcept { derived_quantity, "NTTP type description"> dist{}; dist += 1 * m; @@ -363,8 +362,7 @@ static_assert(quantity{123}.quantity_spec == kind_of); #if MP_UNITS_HOSTED using namespace std::chrono_literals; static_assert(std::is_same_v); -// return type for "s" is not specified. is double for msvc -// static_assert(std::is_same_v); +static_assert(std::is_same_v); static_assert(quantity{24h}.unit == si::hour); static_assert(quantity{24h}.quantity_spec == kind_of); #endif @@ -463,10 +461,10 @@ static_assert((std::uint8_t{255}* m %= 257 * m).numerical_value_in(m) != [] { #if !(defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 18 && defined MP_UNITS_MODULES) // next two lines trigger conversions warnings // (warning disabled in CMake for this file) -static_assert(((22 * m) *= 33.33).numerical_value_in(m) == 733); -static_assert(((22 * m) /= 3.33).numerical_value_in(m) == 6); -static_assert(((22 * m) *= 33.33 * one).numerical_value_in(m) == 733); -static_assert(((22 * m) /= 3.33 * one).numerical_value_in(m) == 6); +static_assert((22 * m *= 33.33).numerical_value_in(m) == 733); +static_assert((22 * m /= 3.33).numerical_value_in(m) == 6); +static_assert((22 * m *= 33.33 * one).numerical_value_in(m) == 733); +static_assert((22 * m /= 3.33 * one).numerical_value_in(m) == 6); #endif template typename Q> @@ -852,30 +850,27 @@ static_assert(2 * one / (1 * m) == 2 / (1 * m)); // equality operators /////////////////////// -static_assert(std::equality_comparable_with, quantity<(si::metre)>>); -static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity<(si::metre)>>); -static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity, int>>); +static_assert(std::equality_comparable_with, quantity>); +static_assert(std::equality_comparable_with, quantity>); static_assert( - std::equality_comparable_with, quantity, int>>); -static_assert(std::equality_comparable_with, quantity<(si::metre)>>); -static_assert(std::equality_comparable_with, quantity<(si::metre), int>>); -static_assert( - std::equality_comparable_with, quantity<(si::kilo<(si::metre)>), int>>); -static_assert(std::equality_comparable_with, quantity<(isq::height[(si::metre)])>>); -static_assert( - std::equality_comparable_with, quantity<(isq::height[(si::metre)]), int>>); -static_assert(std::equality_comparable_with, - quantity<(isq::height[(si::kilo<(si::metre)>)]), int>>); + std::equality_comparable_with, quantity], int>>); template concept no_crossdimensional_equality = requires { requires !requires { 1 * s == 1 * M; }; requires !requires { 1 * s != 1 * M; }; }; -static_assert(no_crossdimensional_equality<(si::metre)>); +static_assert(no_crossdimensional_equality); // same type static_assert(123 * m == 123 * m); @@ -928,7 +923,7 @@ concept no_crossdimensional_ordering = requires { requires !requires { 1 * s <= 1 * M; }; requires !requires { 1 * s >= 1 * M; }; }; -static_assert(no_crossdimensional_ordering<(si::metre)>); +static_assert(no_crossdimensional_ordering); // same type static_assert(123 * m < 321 * m); @@ -1042,35 +1037,34 @@ static_assert(is_of_type(lvalue_q), quantity, (isq::length)>); -static_assert(QuantityOf, (isq::length)>); -static_assert(QuantityOf, (isq::length)>); -static_assert(!QuantityOf, (isq::width)>); -static_assert(QuantityOf, (isq::width)>); -static_assert(QuantityOf, (isq::position_vector)>); -static_assert(QuantityOf[m]>, (isq::width)>); -static_assert(QuantityOf[m]>, (isq::position_vector)>); -static_assert(!QuantityOf, isq::altitude>); +static_assert(QuantityOf, isq::length>); +static_assert(QuantityOf, isq::length>); +static_assert(QuantityOf, isq::length>); +static_assert(!QuantityOf, isq::width>); +static_assert(QuantityOf, isq::width>); +static_assert(QuantityOf, isq::position_vector>); +static_assert(QuantityOf[m]>, isq::width>); +static_assert(QuantityOf[m]>, isq::position_vector>); +static_assert(!QuantityOf, isq::altitude>); -static_assert(QuantityOf, (isq::speed)>); -static_assert(QuantityOf, (isq::length) / (isq::time)>); +static_assert(QuantityOf, isq::speed>); +static_assert(QuantityOf, isq::length / isq::time>); static_assert(QuantityOf, isq::length / isq::time>); -static_assert(QuantityOf[m / s]>, (isq::length) / (isq::time)>); -static_assert(!QuantityOf, (isq::distance) / (isq::duration)>); -static_assert(!QuantityOf, (isq::width) / (isq::duration)>); +static_assert(QuantityOf[m / s]>, isq::length / isq::time>); +static_assert(!QuantityOf, isq::distance / isq::duration>); +static_assert(!QuantityOf, isq::width / isq::duration>); static_assert(QuantityOf, isq::width / isq::duration>); -static_assert(QuantityOf[m / s]>, (isq::width) / (isq::duration)>); -static_assert(!QuantityOf, (isq::position_vector) / (isq::duration)>); +static_assert(QuantityOf[m / s]>, isq::width / isq::duration>); +static_assert(!QuantityOf, isq::position_vector / isq::duration>); static_assert(QuantityOf, isq::position_vector / isq::duration>); -static_assert(QuantityOf[m / s]>, isq::position_vector / isq::duration>); -static_assert(QuantityOf, isq::position_vector / isq::duration>); +static_assert(QuantityOf[m / s]>, isq::position_vector / isq::duration>); +static_assert(QuantityOf, isq::position_vector / isq::duration>); -static_assert(QuantityOf); // kind of -static_assert(QuantityOf[m]), (isq::height)>); // kind of -static_assert(!QuantityOf); // different kinds -static_assert(!QuantityOf); // different kinds -static_assert(QuantityOf); -static_assert( - QuantityOf); // derived unnamed quantity +static_assert(QuantityOf); // kind of +static_assert(QuantityOf[m]), isq::height>); // kind of +static_assert(!QuantityOf); // different kinds +static_assert(!QuantityOf); // different kinds +static_assert(QuantityOf); +static_assert(QuantityOf); // derived unnamed quantity } // namespace diff --git a/test/static/reference_test.cpp b/test/static/reference_test.cpp index 46026702..65abe0bb 100644 --- a/test/static/reference_test.cpp +++ b/test/static/reference_test.cpp @@ -34,8 +34,8 @@ namespace { using namespace mp_units; -using dimensionless_ = struct mp_units::dimensionless; -using one_ = struct mp_units::one; +using dimensionless_ = struct dimensionless; +using one_ = struct one; // base dimensions // clang-format off @@ -238,7 +238,7 @@ template concept invalid_nu_unit = !requires { dim[unit]; }; static_assert(invalid_nu_unit); -static_assert(invalid_nu_unit<(nu::time), second>); +static_assert(invalid_nu_unit); static_assert(invalid_nu_unit); static_assert(invalid_nu_unit); static_assert(invalid_nu_unit); diff --git a/test/static/si_test.cpp b/test/static/si_test.cpp index d52a8edc..4f306fd2 100644 --- a/test/static/si_test.cpp +++ b/test/static/si_test.cpp @@ -65,7 +65,7 @@ concept can_not_be_prefixed = Unit && !requires { typename prefix< static_assert(can_not_be_prefixed); static_assert(can_not_be_prefixed); -static_assert(can_not_be_prefixed)>); +static_assert(can_not_be_prefixed>); static_assert(can_not_be_prefixed); static_assert(can_not_be_prefixed * si::degree>); diff --git a/test/static/unit_test.cpp b/test/static/unit_test.cpp index c16ea66a..ba7ecb4c 100644 --- a/test/static/unit_test.cpp +++ b/test/static/unit_test.cpp @@ -35,8 +35,8 @@ namespace { using namespace mp_units; using namespace mp_units::detail; -using one_ = struct mp_units::one; -using percent_ = struct mp_units::percent; +using one_ = struct one; +using percent_ = struct percent; // base dimensions // clang-format off From 4f4da588b1e7187ca55c5ea70224d3640de88dde Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:15:24 +0200 Subject: [PATCH 42/44] [msvc][fix] remove MP_UNITS_CONSTRAINED_AUTO_WORKAROUND in example --- example/measurement.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/measurement.cpp b/example/measurement.cpp index d61c8d2e..b0cf594b 100644 --- a/example/measurement.cpp +++ b/example/measurement.cpp @@ -151,7 +151,7 @@ void example() const auto acceleration = isq::acceleration(measurement{9.8, 0.1} * m / s2); const auto time = measurement{1.2, 0.1} * s; - const MP_UNITS_CONSTRAINED_AUTO_WORKAROUND(QuantityOf) auto velocity = acceleration * time; + const QuantityOf auto velocity = acceleration * time; std::cout << acceleration << " * " << time << " = " << velocity << " = " << velocity.in(km / h) << '\n'; const auto length = measurement{123., 1.} * m; From 5ecb6c295a17f27cf017f3fe99b900b4648b9199 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 10 Sep 2024 11:01:15 +0200 Subject: [PATCH 43/44] [msvc][fix] add Todo comment for bug https://developercommunity.visualstudio.com/t/Discrepancy-in-Behavior-of-operator-an/10732445 --- src/core/include/mp-units/framework/quantity.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index b2280ef0..18490e07 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -435,6 +435,8 @@ public: } friend constexpr decltype(auto) operator*=(FwdQ&& lhs, const Value& v) { + // TODO use *= when compiiler bug is resolved: + // https://developercommunity.visualstudio.com/t/Discrepancy-in-Behavior-of-operator-an/10732445 lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ * v; return std::forward(lhs); } @@ -447,6 +449,8 @@ public: } friend constexpr decltype(auto) operator*=(FwdQ1&& lhs, const Q2& rhs) { + // TODO use *= when compiiler bug is resolved: + // https://developercommunity.visualstudio.com/t/Discrepancy-in-Behavior-of-operator-an/10732445 lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ * rhs.numerical_value_is_an_implementation_detail_; return std::forward(lhs); @@ -461,6 +465,8 @@ public: friend constexpr decltype(auto) operator/=(FwdQ&& lhs, const Value& v) { MP_UNITS_EXPECTS_DEBUG(v != quantity_values::zero()); + // TODO use /= when compiiler bug is resolved: + // https://developercommunity.visualstudio.com/t/Discrepancy-in-Behavior-of-operator-an/10732445 lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ / v; return std::forward(lhs); } @@ -474,6 +480,8 @@ public: friend constexpr decltype(auto) operator/=(FwdQ1&& lhs, const Q2& rhs) { MP_UNITS_EXPECTS_DEBUG(rhs != rhs.zero()); + // TODO use /= when compiiler bug is resolved: + // https://developercommunity.visualstudio.com/t/Discrepancy-in-Behavior-of-operator-an/10732445 lhs.numerical_value_is_an_implementation_detail_ = lhs.numerical_value_is_an_implementation_detail_ / rhs.numerical_value_is_an_implementation_detail_; return std::forward(lhs); From 329b17ec8cee155dc9cae0b0e00ba85aeea81266 Mon Sep 17 00:00:00 2001 From: Jonas Hoppe <162709928+czjhoppe@users.noreply.github.com> Date: Tue, 10 Sep 2024 11:14:45 +0200 Subject: [PATCH 44/44] clang-format --- src/core/include/mp-units/framework/quantity_spec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/include/mp-units/framework/quantity_spec.h b/src/core/include/mp-units/framework/quantity_spec.h index 7672ba02..ef21e47e 100644 --- a/src/core/include/mp-units/framework/quantity_spec.h +++ b/src/core/include/mp-units/framework/quantity_spec.h @@ -684,7 +684,7 @@ struct ingredients_less : std::bool_constant<(lhs_compl > rhs_compl) || (lhs_compl == rhs_compl && ingredients_dimension_less(Lhs::dimension, Rhs::dimension)) || (lhs_compl == rhs_compl && Lhs::dimension == Rhs::dimension && - detail::type_name() < detail::type_name())>{}; + detail::type_name() < detail::type_name())> {}; template using type_list_of_ingredients_less = expr_less;