forked from mpusz/mp-units
refactor: convertible() renamed to interconvertible()
This commit is contained in:
@@ -212,7 +212,7 @@ struct derived_dimension_impl : detail::expr_fractions<derived_dimension<>, Ds..
|
||||
template<DerivedDimensionSpec... Ds>
|
||||
struct derived_dimension : detail::derived_dimension_impl<Ds...> {
|
||||
template<typename Self, Unit U>
|
||||
requires valid_unit_for_dimension<U, Self> || (sizeof...(Ds) == 0 && convertible(U{}, one))
|
||||
requires valid_unit_for_dimension<U, Self> || (sizeof...(Ds) == 0 && interconvertible(U{}, one))
|
||||
[[nodiscard]] constexpr auto operator[](this const Self, U)
|
||||
{
|
||||
return reference<Self{}, U{}>{};
|
||||
@@ -227,7 +227,7 @@ struct derived_dimension;
|
||||
template<DerivedDimensionSpec... Ds>
|
||||
struct derived_dimension<Ds...> : detail::derived_dimension_impl<Ds...> {
|
||||
template<Unit U>
|
||||
requires valid_unit_for_dimension<U, derived_dimension> || (sizeof...(Ds) == 0 && convertible(U{}, one))
|
||||
requires valid_unit_for_dimension<U, derived_dimension> || (sizeof...(Ds) == 0 && interconvertible(U{}, one))
|
||||
[[nodiscard]] constexpr auto operator[](U) const
|
||||
{
|
||||
return reference<derived_dimension{}, U{}>{};
|
||||
@@ -238,7 +238,7 @@ template<typename Self, DerivedDimension D>
|
||||
struct derived_dimension<Self, D> : D {
|
||||
template<Unit U>
|
||||
requires valid_unit_for_dimension<U, Self> ||
|
||||
(convertible(derived_dimension{}, derived_dimension<>{}) && convertible(U{}, one))
|
||||
(interconvertible(derived_dimension{}, derived_dimension<>{}) && interconvertible(U{}, one))
|
||||
[[nodiscard]] constexpr auto operator[](U) const
|
||||
{
|
||||
return reference<Self{}, U{}>{};
|
||||
@@ -325,7 +325,7 @@ template<Dimension Lhs, Dimension Rhs>
|
||||
}
|
||||
|
||||
template<Dimension D1, Dimension D2>
|
||||
[[nodiscard]] consteval bool convertible(D1, D2)
|
||||
[[nodiscard]] consteval bool interconvertible(D1, D2)
|
||||
{
|
||||
return std::derived_from<D1, D2> || std::derived_from<D2, D1>;
|
||||
}
|
||||
@@ -383,7 +383,7 @@ concept associated_unit = Unit<U> && requires(U u) { get_dimension_for_impl(get_
|
||||
}
|
||||
|
||||
template<Unit auto U, Dimension auto Dim>
|
||||
requires requires { detail::get_dimension_for(U); } && (convertible(Dim, detail::get_dimension_for(U)))
|
||||
requires requires { detail::get_dimension_for(U); } && (interconvertible(Dim, detail::get_dimension_for(U)))
|
||||
inline constexpr bool is_valid_unit_for_dimension<U, Dim> = true;
|
||||
|
||||
} // namespace detail
|
||||
@@ -402,7 +402,7 @@ namespace std {
|
||||
* the two provided.
|
||||
*/
|
||||
template<units::Dimension D1, units::Dimension D2>
|
||||
requires(units::convertible(D1{}, D2{}))
|
||||
requires(units::interconvertible(D1{}, D2{}))
|
||||
struct common_type<D1, D2> {
|
||||
using type = ::units::conditional<std::derived_from<std::remove_const_t<D1>, std::remove_const_t<D2>>,
|
||||
std::remove_const_t<D1>, std::remove_const_t<D2>>;
|
||||
|
||||
@@ -70,7 +70,7 @@ concept harmonic_ = // exposition only
|
||||
template<typename QFrom, typename QTo>
|
||||
concept quantity_convertible_to_ = // exposition only
|
||||
Quantity<QFrom> && Quantity<QTo> &&
|
||||
convertible(QFrom::reference, QTo::reference) && scalable_with_<typename QFrom::rep, typename QTo::rep> &&
|
||||
interconvertible(QFrom::reference, QTo::reference) && scalable_with_<typename QFrom::rep, typename QTo::rep> &&
|
||||
(floating_point_<QTo> || (!floating_point_<QFrom> && harmonic_<QFrom, QTo>));
|
||||
|
||||
template<typename Func, typename T, typename U>
|
||||
@@ -470,7 +470,7 @@ explicit quantity(Q) -> quantity<reference<quantity_like_traits<Q>::dimension, q
|
||||
|
||||
// non-member binary operators
|
||||
template<Quantity Q1, Quantity Q2>
|
||||
requires(convertible(Q1::reference, Q2::reference)) &&
|
||||
requires(interconvertible(Q1::reference, Q2::reference)) &&
|
||||
quantity_value_for_<std::plus<>, typename Q1::rep, typename Q2::rep>
|
||||
[[nodiscard]] constexpr Quantity auto operator+(const Q1& lhs, const Q2& rhs)
|
||||
{
|
||||
@@ -480,7 +480,7 @@ template<Quantity Q1, Quantity Q2>
|
||||
}
|
||||
|
||||
template<Quantity Q1, Quantity Q2>
|
||||
requires(convertible(Q1::reference, Q2::reference)) &&
|
||||
requires(interconvertible(Q1::reference, Q2::reference)) &&
|
||||
quantity_value_for_<std::minus<>, typename Q1::rep, typename Q2::rep>
|
||||
[[nodiscard]] constexpr Quantity auto operator-(const Q1& lhs, const Q2& rhs)
|
||||
{
|
||||
@@ -506,7 +506,7 @@ template<Quantity Q1, Quantity Q2>
|
||||
|
||||
template<Quantity Q1, Quantity Q2>
|
||||
requires(!floating_point_<typename Q1::rep>) && (!floating_point_<typename Q2::rep>) &&
|
||||
(convertible(Q1::reference, Q2::reference) || quantity_of<Q2, dimension_one>) &&
|
||||
(interconvertible(Q1::reference, Q2::reference) || quantity_of<Q2, dimension_one>) &&
|
||||
quantity_value_for_<std::modulus<>, typename Q1::rep, typename Q2::rep>
|
||||
[[nodiscard]] constexpr Quantity auto operator%(const Q1& lhs, const Q2& rhs)
|
||||
{
|
||||
@@ -517,7 +517,7 @@ template<Quantity Q1, Quantity Q2>
|
||||
}
|
||||
|
||||
template<Quantity Q1, Quantity Q2>
|
||||
requires(convertible(Q1::reference, Q2::reference)) &&
|
||||
requires(interconvertible(Q1::reference, Q2::reference)) &&
|
||||
std::three_way_comparable_with<typename Q1::rep, typename Q2::rep>
|
||||
[[nodiscard]] constexpr auto operator<=>(const Q1& lhs, const Q2& rhs)
|
||||
{
|
||||
@@ -526,7 +526,7 @@ template<Quantity Q1, Quantity Q2>
|
||||
}
|
||||
|
||||
template<Quantity Q1, Quantity Q2>
|
||||
requires(convertible(Q1::reference, Q2::reference)) &&
|
||||
requires(interconvertible(Q1::reference, Q2::reference)) &&
|
||||
std::equality_comparable_with<typename Q1::rep, typename Q2::rep>
|
||||
[[nodiscard]] constexpr bool operator==(const Q1& lhs, const Q2& rhs)
|
||||
{
|
||||
|
||||
@@ -85,7 +85,7 @@ struct cast_traits<From, To> {
|
||||
* @tparam To a target quantity type to cast to
|
||||
*/
|
||||
template<Quantity To, auto R, scalable_with_<typename To::rep> Rep>
|
||||
requires(convertible(To::reference, R))
|
||||
requires(interconvertible(To::reference, R))
|
||||
[[nodiscard]] constexpr auto quantity_cast(const quantity<R, Rep>& q)
|
||||
{
|
||||
if constexpr (R.unit == To::unit) {
|
||||
@@ -122,7 +122,7 @@ template<Quantity To, auto R, scalable_with_<typename To::rep> Rep>
|
||||
* @tparam ToU a unit type to use for a target quantity
|
||||
*/
|
||||
template<Reference auto ToR, auto R, typename Rep>
|
||||
requires(convertible(ToR, R))
|
||||
requires(interconvertible(ToR, R))
|
||||
[[nodiscard]] constexpr auto quantity_cast(const quantity<R, Rep>& q)
|
||||
{
|
||||
return quantity_cast<quantity<ToR, Rep>>(q);
|
||||
@@ -142,7 +142,7 @@ template<Reference auto ToR, auto R, typename Rep>
|
||||
* @tparam ToD a dimension type to use for a target quantity
|
||||
*/
|
||||
template<Dimension auto ToD, auto R, typename Rep>
|
||||
requires(convertible(ToD, R.dimension))
|
||||
requires(interconvertible(ToD, R.dimension))
|
||||
[[nodiscard]] constexpr auto quantity_cast(const quantity<R, Rep>& q)
|
||||
{
|
||||
constexpr reference<ToD, quantity<R, Rep>::unit> r;
|
||||
@@ -162,7 +162,7 @@ template<Dimension auto ToD, auto R, typename Rep>
|
||||
* @tparam ToU a unit type to use for a target quantity
|
||||
*/
|
||||
template<Unit auto ToU, auto R, typename Rep>
|
||||
requires(convertible(ToU, R.unit))
|
||||
requires(interconvertible(ToU, R.unit))
|
||||
[[nodiscard]] constexpr auto quantity_cast(const quantity<R, Rep>& q)
|
||||
{
|
||||
constexpr reference<quantity<R, Rep>::dimension, ToU> r;
|
||||
|
||||
@@ -102,9 +102,9 @@ template<Representation Rep, Reference R>
|
||||
void /*Use `q * (1 * r)` rather than `q * r`.*/ operator*(Quantity auto, Reference auto) = delete;
|
||||
|
||||
template<Reference R1, Reference R2>
|
||||
[[nodiscard]] consteval bool convertible(R1, R2)
|
||||
[[nodiscard]] consteval bool interconvertible(R1, R2)
|
||||
{
|
||||
return convertible(R1::dimension, R2::dimension) && convertible(R1::unit, R2::unit);
|
||||
return interconvertible(R1::dimension, R2::dimension) && interconvertible(R1::unit, R2::unit);
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ struct system_reference {
|
||||
static constexpr auto coherent_unit = CoU;
|
||||
|
||||
template<Unit U>
|
||||
requires(convertible(coherent_unit, U{}))
|
||||
requires(interconvertible(coherent_unit, U{}))
|
||||
[[nodiscard]] constexpr reference<dimension, U{}> operator[](U) const
|
||||
{
|
||||
return {};
|
||||
|
||||
@@ -531,7 +531,7 @@ template<Unit Lhs, Unit Rhs>
|
||||
|
||||
// Convertible
|
||||
template<Unit Lhs, Unit Rhs>
|
||||
[[nodiscard]] consteval bool convertible(Lhs lhs, Rhs rhs)
|
||||
[[nodiscard]] consteval bool interconvertible(Lhs lhs, Rhs rhs)
|
||||
{
|
||||
auto canonical_lhs = detail::get_canonical_unit(lhs);
|
||||
auto canonical_rhs = detail::get_canonical_unit(rhs);
|
||||
@@ -827,7 +827,7 @@ template<typename U1, typename U2>
|
||||
namespace std {
|
||||
|
||||
template<units::Unit U1, units::Unit U2>
|
||||
requires(units::convertible(U1{}, U2{}))
|
||||
requires(units::interconvertible(U1{}, U2{}))
|
||||
struct common_type<U1, U2> {
|
||||
using type = std::remove_const_t<decltype(::units::detail::common_type_impl(U1{}, U2{}))>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user