diff --git a/src/core/include/mp-units/framework/quantity.h b/src/core/include/mp-units/framework/quantity.h index c9614266..af641474 100644 --- a/src/core/include/mp-units/framework/quantity.h +++ b/src/core/include/mp-units/framework/quantity.h @@ -314,25 +314,13 @@ public: convert_explicitly> || !std::convertible_to::rep>) constexpr // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) - operator Q_() const& noexcept( - noexcept(quantity_like_traits::from_numerical_value(numerical_value_is_an_implementation_detail_)) && - std::is_nothrow_copy_constructible_v) + operator Q_() const + noexcept(noexcept(quantity_like_traits::from_numerical_value(numerical_value_is_an_implementation_detail_)) && + std::is_nothrow_copy_constructible_v) { - return quantity_like_traits::from_numerical_value(numerical_value_is_an_implementation_detail_).value; - } - - template> - requires detail::QuantityConvertibleTo> - [[nodiscard]] explicit(is_specialization_of::from_numerical_value( - numerical_value_is_an_implementation_detail_)), - convert_explicitly> || - !std::convertible_to::rep>) constexpr - // NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions) - operator Q_() && noexcept( - noexcept(quantity_like_traits::from_numerical_value(numerical_value_is_an_implementation_detail_)) && - std::is_nothrow_move_constructible_v) - { - return quantity_like_traits::from_numerical_value(std::move(numerical_value_is_an_implementation_detail_)).value; + return quantity_like_traits::from_numerical_value( + numerical_value_in(get_unit(quantity_like_traits::reference))) + .value; } // member unary operators diff --git a/test/static/chrono_test.cpp b/test/static/chrono_test.cpp index 9f3b1901..8c532390 100644 --- a/test/static/chrono_test.cpp +++ b/test/static/chrono_test.cpp @@ -127,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);