diff --git a/example/kalman_filter/kalman_filter-example_1.cpp b/example/kalman_filter/kalman_filter-example_1.cpp index 5c73a441..c53f8c7e 100644 --- a/example/kalman_filter/kalman_filter-example_1.cpp +++ b/example/kalman_filter/kalman_filter-example_1.cpp @@ -55,11 +55,11 @@ int main() print_header(initial); state next = initial; - for (int index = 1; const auto& m : measurements) { + for (int index = 1; const auto& v : measurements) { const auto& previous = next; const auto gain = 1. / index * one; - const auto current = state_update(previous, m, gain); + const auto current = state_update(previous, v, gain); next = current; - print(index++, gain, m, current, next); + print(index++, gain, v, current, next); } } diff --git a/src/core/include/mp-units/bits/magnitude.h b/src/core/include/mp-units/bits/magnitude.h index ae12b527..27e86d8e 100644 --- a/src/core/include/mp-units/bits/magnitude.h +++ b/src/core/include/mp-units/bits/magnitude.h @@ -194,7 +194,7 @@ template } template -[[nodiscard]] consteval ratio get_exponent(Element) +[[nodiscard]] CONSTEVAL ratio get_exponent(Element) { if constexpr (detail::is_specialization_of_power_v) return Element::exponent; diff --git a/src/core/include/mp-units/bits/quantity_concepts.h b/src/core/include/mp-units/bits/quantity_concepts.h index a544be61..cb1a5694 100644 --- a/src/core/include/mp-units/bits/quantity_concepts.h +++ b/src/core/include/mp-units/bits/quantity_concepts.h @@ -39,7 +39,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(std::remove_reference_t* t) { to_base_specialization_of_quantity(t); }; } // namespace detail diff --git a/src/core/include/mp-units/bits/sudo_cast.h b/src/core/include/mp-units/bits/sudo_cast.h index 04546df4..8da1f0c5 100644 --- a/src/core/include/mp-units/bits/sudo_cast.h +++ b/src/core/include/mp-units/bits/sudo_cast.h @@ -59,7 +59,8 @@ template // TODO how to constrain the second part here? [[nodiscard]] constexpr Quantity auto sudo_cast(From&& q) { - if constexpr (std::remove_reference_t::unit == To::unit) { + constexpr auto q_unit = std::remove_reference_t::unit; + if constexpr (q_unit == To::unit) { // no scaling of the number needed return make_quantity( static_cast(std::forward(q).number())); // this is the only (and recommended) way to do @@ -68,7 +69,7 @@ template // warnings on conversions } else { // scale the number - constexpr Magnitude auto c_mag = get_canonical_unit(q.unit).mag / get_canonical_unit(To::unit).mag; + constexpr Magnitude auto c_mag = get_canonical_unit(q_unit).mag / get_canonical_unit(To::unit).mag; constexpr Magnitude auto num = numerator(c_mag); constexpr Magnitude auto den = denominator(c_mag); constexpr Magnitude auto irr = c_mag * (den / num); diff --git a/src/core/include/mp-units/bits/value_cast.h b/src/core/include/mp-units/bits/value_cast.h index 92880e16..27c6d268 100644 --- a/src/core/include/mp-units/bits/value_cast.h +++ b/src/core/include/mp-units/bits/value_cast.h @@ -42,7 +42,7 @@ namespace mp_units { */ template [[nodiscard]] constexpr Quantity auto value_cast(Q&& q) - requires Quantity> && (convertible(q.reference, ToU)) + requires Quantity> && (convertible(std::remove_reference_t::reference, ToU)) { using q_type = std::remove_reference_t; constexpr auto r = [] { @@ -71,7 +71,7 @@ template std::constructible_from::rep> [[nodiscard]] constexpr quantity::reference, ToRep> value_cast(Q&& q) { - return detail::sudo_cast>(std::forward(q)); + return detail::sudo_cast::reference, ToRep>>(std::forward(q)); } } // namespace mp_units diff --git a/src/core/include/mp-units/quantity.h b/src/core/include/mp-units/quantity.h index f8f7f6de..850cf624 100644 --- a/src/core/include/mp-units/quantity.h +++ b/src/core/include/mp-units/quantity.h @@ -326,7 +326,7 @@ public: private: template requires quantity>::_rep_safe_constructible_ - friend constexpr quantity> make_quantity(Rep2&& v); + friend constexpr quantity> make_quantity(Rep2&&); template requires detail::RepSafeConstructibleFrom diff --git a/src/core/include/mp-units/quantity_spec.h b/src/core/include/mp-units/quantity_spec.h index 34280967..0b351508 100644 --- a/src/core/include/mp-units/quantity_spec.h +++ b/src/core/include/mp-units/quantity_spec.h @@ -115,15 +115,15 @@ struct quantity_spec_interface { return make_quantity::unit>{}>(std::forward(q).number()); } #else - template U> + template U> [[nodiscard]] consteval Reference auto operator[](U u) const { return reference{}; } - template + template requires Quantity> && - (explicitly_convertible(std::remove_reference_t::quantity_spec, Self{})) + (explicitly_convertible(std::remove_reference_t::quantity_spec, Self_{})) [[nodiscard]] constexpr Quantity auto operator()(Q&& q) const { return make_quantity::unit>{}>(std::forward(q).number()); @@ -291,15 +291,15 @@ struct quantity_spec : std::remove_const_t { static constexpr quantity_character character = detail::quantity_character_init(QS.character); #ifndef __cpp_explicit_this_parameter - template U> + template U> [[nodiscard]] consteval Reference auto operator[](U u) const { return reference{}; } - template + template requires Quantity> && - (explicitly_convertible(std::remove_reference_t::quantity_spec, Self{})) + (explicitly_convertible(std::remove_reference_t::quantity_spec, Self_{})) [[nodiscard]] constexpr Quantity auto operator()(Q&& q) const { return make_quantity::unit>{}>(std::forward(q).number()); @@ -438,9 +438,6 @@ QUANTITY_SPEC(dimensionless, derived_quantity_spec<>{}); * * Specifies that the provided `Q` should be treated as a quantity kind. */ -template -struct kind_of_; - namespace detail { template @@ -448,13 +445,21 @@ concept QuantitySpecWithNoSpecifiers = detail::NamedQuantitySpec || detail::I } // namespace detail +#ifdef __cpp_explicit_this_parameter template requires(get_kind(Q) == Q) -#ifdef __cpp_explicit_this_parameter struct kind_of_ : Q { static constexpr auto _quantity_spec_ = Q; }; #else + +#if UNITS_COMP_CLANG +template + requires detail::QuantitySpecWithNoSpecifiers> && (get_kind(Q) == Q) +#else +template + requires(get_kind(Q) == Q) +#endif struct kind_of_ : quantity_spec, Q> { static constexpr auto _quantity_spec_ = Q; }; @@ -867,8 +872,8 @@ struct extract_results { #if UNITS_COMP_CLANG -template -extract_results(bool, Ts...) -> extract_results; +template +extract_results(bool, From = {}, To = {}, prepend_rest = {}, Elem = {}) -> extract_results; #endif diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index fd8f2170..05858dd9 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -850,7 +850,7 @@ static_assert(10 * isq::mechanical_energy[J] == 5 * isq::force[N] * (2 * isq::le static_assert(1 * si::si2019::speed_of_light_in_vacuum == 299'792'458 * isq::speed[m / s]); // Different named dimensions -template +template // TODO Use `Reference` when Clang supports it. concept invalid_comparison = !requires { 2 * R1 == 2 * R2; } && !requires { 2 * R2 == 2 * R1; }; static_assert(invalid_comparison);