mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 04:44:27 +02:00
[[nodiscard]] added to quantity_cast and DESIGN.md update with the new quantity_cast functionality
This commit is contained in:
@@ -392,11 +392,17 @@ a `quantity` type or only its template parameters (`Unit`, `Rep`):
|
||||
|
||||
```cpp
|
||||
template<Quantity To, typename U, typename Rep>
|
||||
requires std::same_as<typename To::dimension, typename U::dimension>
|
||||
constexpr To quantity_cast(const quantity<U, Rep>& q);
|
||||
requires same_dim<typename To::dimension, typename U::dimension>
|
||||
[[nodiscard]] constexpr To quantity_cast(const quantity<U, Rep>& q);
|
||||
|
||||
template<Unit ToU, Scalar ToRep = double, typename U, typename Rep>
|
||||
constexpr quantity<ToU, ToRep> quantity_cast(const quantity<U, Rep>& q);
|
||||
template<Unit ToU, Scalar ToRep, typename U, typename Rep>
|
||||
[[nodiscard]] constexpr quantity<ToU, ToRep> quantity_cast(const quantity<U, Rep>& q);
|
||||
|
||||
template<Unit ToU, typename U, typename Rep>
|
||||
[[nodiscard]] constexpr quantity<ToU, Rep> quantity_cast(const quantity<U, Rep>& q);
|
||||
|
||||
template<Scalar ToRep, typename U, typename Rep>
|
||||
[[nodiscard]] constexpr quantity<U, ToRep> quantity_cast(const quantity<U, Rep>& q);
|
||||
```
|
||||
|
||||
## Strong types instead of aliases, and type downcasting facility
|
||||
|
@@ -126,8 +126,8 @@ namespace units {
|
||||
} // namespace detail
|
||||
|
||||
template<Quantity To, typename U, typename Rep>
|
||||
requires same_dim<typename To::dimension, typename U::dimension>
|
||||
constexpr To quantity_cast(const quantity<U, Rep>& q)
|
||||
[[nodiscard]] constexpr To quantity_cast(const quantity<U, Rep>& q)
|
||||
requires same_dim<typename To::dimension, typename U::dimension>
|
||||
{
|
||||
using c_ratio = ratio_divide<typename U::ratio, typename To::unit::ratio>;
|
||||
using c_rep = std::common_type_t<typename To::rep, Rep, intmax_t>;
|
||||
@@ -136,17 +136,17 @@ namespace units {
|
||||
}
|
||||
|
||||
template<Unit ToU, Scalar ToRep, typename U, typename Rep>
|
||||
constexpr quantity<ToU, ToRep> quantity_cast(const quantity<U, Rep>& q)
|
||||
[[nodiscard]] constexpr quantity<ToU, ToRep> quantity_cast(const quantity<U, Rep>& q)
|
||||
{
|
||||
return quantity_cast<quantity<ToU, ToRep>>(q);
|
||||
}
|
||||
template<Unit ToU, typename U, typename Rep>
|
||||
constexpr quantity<ToU, Rep> quantity_cast(const quantity<U, Rep>& q)
|
||||
[[nodiscard]] constexpr quantity<ToU, Rep> quantity_cast(const quantity<U, Rep>& q)
|
||||
{
|
||||
return quantity_cast<quantity<ToU, Rep>>(q);
|
||||
}
|
||||
template<Scalar ToRep, typename U, typename Rep>
|
||||
constexpr quantity<U, ToRep> quantity_cast(const quantity<U, Rep>& q)
|
||||
[[nodiscard]] constexpr quantity<U, ToRep> quantity_cast(const quantity<U, Rep>& q)
|
||||
{
|
||||
return quantity_cast<quantity<U, ToRep>>(q);
|
||||
}
|
||||
|
Reference in New Issue
Block a user