feat: quantity_of and weak_quantity_of now support references

This commit is contained in:
Mateusz Pusz
2022-11-30 17:57:27 +01:00
parent 872caf460a
commit 77a124a3d9

View File

@@ -101,22 +101,25 @@ inline constexpr bool is_quantity<quantity<R, Rep>> = true;
} // namespace detail } // namespace detail
/** /**
* @brief A concept matching all quantities with provided dimension * @brief A concept matching all quantities with provided dimension or reference
* *
* Satisfied by all quantities with a dimension being the instantiation derived from * Satisfied by all quantities with a dimension/reference being the instantiation derived from
* the provided dimension type. * the provided dimension/reference type.
*/ */
template<typename Q, Dimension auto D> template<typename Q, auto V>
concept quantity_of = Quantity<Q> && Dimension<std::remove_const_t<decltype(D)>> && (Q::dimension == D); concept quantity_of = Quantity<Q> && ((Dimension<std::remove_const_t<decltype(V)>> && Q::dimension == V) ||
(Reference<std::remove_const_t<decltype(V)>> && Q::reference == V));
/** /**
* @brief A concept matching all quantities with provided dimension or reference * @brief A concept matching all quantities with provided dimension or reference
* *
* Satisfied by all quantities with a dimension being the instantiation derived from * Satisfied by all quantities with a dimension/reference being the instantiation derived from
* the provided dimension type. * the provided dimension/reference type.
*/ */
template<typename Q, Dimension auto D> template<typename Q, auto V>
concept weak_quantity_of = Quantity<Q> && Dimension<std::remove_const_t<decltype(D)>> && concept weak_quantity_of = Quantity<Q> &&
(interconvertible(Q::dimension, D)); ((Dimension<std::remove_const_t<decltype(V)>> && interconvertible(Q::dimension, V)) ||
(Reference<std::remove_const_t<decltype(V)>> &&
interconvertible(Q::dimension, V.dimension) && Q::unit == V.unit));
} // namespace units } // namespace units