diff --git a/example/avg_velocity.cpp b/example/avg_velocity.cpp index 5c34003a..1b470eb3 100644 --- a/example/avg_velocity.cpp +++ b/example/avg_velocity.cpp @@ -123,7 +123,7 @@ void example() // conversion from a floating-point to an integral type is a truncating one so an explicit cast is needed // also it is not possible to make a lossless conversion of miles to meters on an integral type // (explicit cast needed) - print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast(distance), quantity_cast(duration))); + print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast>(distance), quantity_cast(duration))); print_result(distance, duration, fixed_double_si_avg_speed(distance, duration)); print_result(distance, duration, si_avg_speed(distance, duration)); diff --git a/src/include/units/quantity.h b/src/include/units/quantity.h index 340e6801..673b9552 100644 --- a/src/include/units/quantity.h +++ b/src/include/units/quantity.h @@ -164,19 +164,17 @@ template * Implicit conversions between quantities of different types are allowed only for "safe" * (i.e. non-truncating) conversion. In such cases an explicit cast have to be used. * - * This cast gets both the target unit and representation to cast to. For example: + * This cast gets only the target dimension to cast to. For example: * - * auto q1 = units::quantity_cast(1ms); + * auto q1 = units::quantity_cast(200Gal); * - * @tparam ToU a unit type to use for a target quantity - * @tparam ToRep a representation type to use for a target quantity + * @tparam ToD a dimension type to use for a target quantity */ -template +template [[nodiscard]] constexpr auto quantity_cast(const quantity& q) - requires UnitOf && - detail::basic_arithmetic> + requires same_dim { - return quantity_cast>(q); + return quantity_cast>(q); } /** @@ -187,7 +185,7 @@ template * * This cast gets only the target unit to cast to. For example: * - * auto q1 = units::quantity_cast(1ms); + * auto q1 = units::quantity_cast(1ms); * * @tparam ToU a unit type to use for a target quantity */