mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 20:54:28 +02:00
quantity_cast refactored
- new version with ToD added - <ToU, Rep> version removed
This commit is contained in:
@@ -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
|
// 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
|
// also it is not possible to make a lossless conversion of miles to meters on an integral type
|
||||||
// (explicit cast needed)
|
// (explicit cast needed)
|
||||||
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<si::metre, int>(distance), quantity_cast<int>(duration)));
|
print_result(distance, duration, fixed_int_si_avg_speed(quantity_cast<si::length<si::metre, int>>(distance), quantity_cast<int>(duration)));
|
||||||
|
|
||||||
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
print_result(distance, duration, fixed_double_si_avg_speed(distance, duration));
|
||||||
print_result(distance, duration, si_avg_speed(distance, duration));
|
print_result(distance, duration, si_avg_speed(distance, duration));
|
||||||
|
@@ -164,19 +164,17 @@ template<Quantity To, typename D, typename U, typename Rep>
|
|||||||
* Implicit conversions between quantities of different types are allowed only for "safe"
|
* 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.
|
* (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<units::second, int>(1ms);
|
* auto q1 = units::quantity_cast<units::si::acceleration>(200Gal);
|
||||||
*
|
*
|
||||||
* @tparam ToU a unit type to use for a target quantity
|
* @tparam ToD a dimension type to use for a target quantity
|
||||||
* @tparam ToRep a representation type to use for a target quantity
|
|
||||||
*/
|
*/
|
||||||
template<Unit ToU, Scalar ToRep, typename D, typename U, typename Rep>
|
template<Dimension ToD, typename D, typename U, typename Rep>
|
||||||
[[nodiscard]] constexpr auto quantity_cast(const quantity<D, U, Rep>& q)
|
[[nodiscard]] constexpr auto quantity_cast(const quantity<D, U, Rep>& q)
|
||||||
requires UnitOf<ToU, D> &&
|
requires same_dim<ToD, D>
|
||||||
detail::basic_arithmetic<std::common_type_t<ToRep, Rep, intmax_t>>
|
|
||||||
{
|
{
|
||||||
return quantity_cast<quantity<D, ToU, ToRep>>(q);
|
return quantity_cast<quantity<ToD, U, Rep>>(q);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -187,7 +185,7 @@ template<Unit ToU, Scalar ToRep, typename D, typename U, typename Rep>
|
|||||||
*
|
*
|
||||||
* This cast gets only the target unit to cast to. For example:
|
* This cast gets only the target unit to cast to. For example:
|
||||||
*
|
*
|
||||||
* auto q1 = units::quantity_cast<units::second>(1ms);
|
* auto q1 = units::quantity_cast<units::si::second>(1ms);
|
||||||
*
|
*
|
||||||
* @tparam ToU a unit type to use for a target quantity
|
* @tparam ToU a unit type to use for a target quantity
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user