refactor: 💥 common_XXX() functions renamed to get_common_XXX()
This is needed to release a name for `common_unit` type that is coming soon.
This commit is contained in:
1 parent
5f9a6e4a20
commit
dcab80525d
13 files changed
+120
-115
No files matched your search
@@ -88,7 +88,7 @@ concept InvocableQuantities =
|
||||
// TODO remove the following when clang diagnostics improve
|
||||
// https://github.com/llvm/llvm-project/issues/96660
|
||||
template<auto R1, auto R2>
|
||||
concept HaveCommonReferenceImpl = requires { common_reference(R1, R2); };
|
||||
concept HaveCommonReferenceImpl = requires { get_common_reference(R1, R2); };
|
||||
|
||||
template<auto R1, auto R2>
|
||||
concept HaveCommonReference = HaveCommonReferenceImpl<R1, R2>;
|
||||
@@ -96,11 +96,11 @@ concept HaveCommonReference = HaveCommonReferenceImpl<R1, R2>;
|
||||
template<typename Func, typename Q1, typename Q2>
|
||||
concept CommonlyInvocableQuantities =
|
||||
Quantity<Q1> && Quantity<Q2> && HaveCommonReference<Q1::reference, Q2::reference> &&
|
||||
InvocableQuantities<Func, Q1, Q2, common_quantity_spec(Q1::quantity_spec, Q2::quantity_spec).character>;
|
||||
InvocableQuantities<Func, Q1, Q2, get_common_quantity_spec(Q1::quantity_spec, Q2::quantity_spec).character>;
|
||||
|
||||
template<typename Func, Quantity Q1, Quantity Q2>
|
||||
requires CommonlyInvocableQuantities<Func, Q1, Q2>
|
||||
using common_quantity_for = quantity<common_reference(Q1::reference, Q2::reference),
|
||||
using common_quantity_for = quantity<get_common_reference(Q1::reference, Q2::reference),
|
||||
std::invoke_result_t<Func, typename Q1::rep, typename Q2::rep>>;
|
||||
|
||||
template<auto R1, auto R2, typename Rep1, typename Rep2>
|
||||
@@ -645,11 +645,11 @@ MP_UNITS_EXPORT_END
|
||||
|
||||
template<mp_units::Quantity Q1, mp_units::Quantity Q2>
|
||||
requires requires {
|
||||
{ mp_units::common_reference(Q1::reference, Q2::reference) } -> mp_units::Reference;
|
||||
{ mp_units::get_common_reference(Q1::reference, Q2::reference) } -> mp_units::Reference;
|
||||
typename std::common_type_t<typename Q1::rep, typename Q2::rep>;
|
||||
}
|
||||
struct std::common_type<Q1, Q2> {
|
||||
using type = mp_units::quantity<mp_units::common_reference(Q1::reference, Q2::reference),
|
||||
using type = mp_units::quantity<mp_units::get_common_reference(Q1::reference, Q2::reference),
|
||||
std::common_type_t<typename Q1::rep, typename Q2::rep>>;
|
||||
};
|
||||
|
||||
|
||||
@@ -1497,12 +1497,12 @@ template<QuantitySpec Q>
|
||||
return kind_of<detail::get_kind_tree_root(Q{})>;
|
||||
}
|
||||
|
||||
[[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q) { return q; }
|
||||
[[nodiscard]] consteval QuantitySpec auto get_common_quantity_spec(QuantitySpec auto q) { return q; }
|
||||
|
||||
template<QuantitySpec Q1, QuantitySpec Q2>
|
||||
requires detail::QuantitySpecConvertibleTo<detail::get_kind_tree_root(Q1{}), detail::get_kind_tree_root(Q2{})> ||
|
||||
detail::QuantitySpecConvertibleTo<detail::get_kind_tree_root(Q2{}), detail::get_kind_tree_root(Q1{})>
|
||||
[[nodiscard]] consteval QuantitySpec auto common_quantity_spec(Q1 q1, Q2 q2)
|
||||
[[nodiscard]] consteval QuantitySpec auto get_common_quantity_spec(Q1 q1, Q2 q2)
|
||||
{
|
||||
using QQ1 = decltype(detail::remove_kind(q1));
|
||||
using QQ2 = decltype(detail::remove_kind(q2));
|
||||
@@ -1535,11 +1535,11 @@ template<QuantitySpec Q1, QuantitySpec Q2>
|
||||
// NOLINTEND(bugprone-branch-clone)
|
||||
}
|
||||
|
||||
[[nodiscard]] consteval QuantitySpec auto common_quantity_spec(QuantitySpec auto q1, QuantitySpec auto q2,
|
||||
QuantitySpec auto q3, QuantitySpec auto... rest)
|
||||
requires requires { common_quantity_spec(common_quantity_spec(q1, q2), q3, rest...); }
|
||||
[[nodiscard]] consteval QuantitySpec auto get_common_quantity_spec(QuantitySpec auto q1, QuantitySpec auto q2,
|
||||
QuantitySpec auto q3, QuantitySpec auto... rest)
|
||||
requires requires { get_common_quantity_spec(get_common_quantity_spec(q1, q2), q3, rest...); }
|
||||
{
|
||||
return common_quantity_spec(common_quantity_spec(q1, q2), q3, rest...);
|
||||
return get_common_quantity_spec(get_common_quantity_spec(q1, q2), q3, rest...);
|
||||
}
|
||||
|
||||
MP_UNITS_EXPORT_END
|
||||
|
||||
@@ -268,26 +268,30 @@ template<Reference R, typename Q>
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
|
||||
constexpr auto operator/(R, Q&& q) = delete;
|
||||
|
||||
[[nodiscard]] consteval AssociatedUnit auto common_reference(AssociatedUnit auto u1, AssociatedUnit auto u2,
|
||||
AssociatedUnit auto... rest)
|
||||
[[nodiscard]] consteval AssociatedUnit auto get_common_reference(AssociatedUnit auto u1, AssociatedUnit auto u2,
|
||||
AssociatedUnit auto... rest)
|
||||
requires requires {
|
||||
{ common_quantity_spec(get_quantity_spec(u1), get_quantity_spec(u2), get_quantity_spec(rest)...) } -> QuantitySpec;
|
||||
{ common_unit(u1, u2, rest...) } -> AssociatedUnit;
|
||||
{
|
||||
get_common_quantity_spec(get_quantity_spec(u1), get_quantity_spec(u2), get_quantity_spec(rest)...)
|
||||
} -> QuantitySpec;
|
||||
{ get_common_unit(u1, u2, rest...) } -> AssociatedUnit;
|
||||
}
|
||||
{
|
||||
return common_unit(u1, u2, rest...);
|
||||
return get_common_unit(u1, u2, rest...);
|
||||
}
|
||||
|
||||
template<Reference R1, Reference R2, Reference... Rest>
|
||||
[[nodiscard]] consteval Reference auto common_reference(R1 r1, R2 r2, Rest... rest)
|
||||
[[nodiscard]] consteval Reference auto get_common_reference(R1 r1, R2 r2, Rest... rest)
|
||||
requires(!(AssociatedUnit<R1> && AssociatedUnit<R2> && (... && AssociatedUnit<Rest>))) && requires {
|
||||
{ common_quantity_spec(get_quantity_spec(r1), get_quantity_spec(r2), get_quantity_spec(rest)...) } -> QuantitySpec;
|
||||
{ common_unit(get_unit(r1), get_unit(r2), get_unit(rest)...) } -> Unit;
|
||||
{
|
||||
get_common_quantity_spec(get_quantity_spec(r1), get_quantity_spec(r2), get_quantity_spec(rest)...)
|
||||
} -> QuantitySpec;
|
||||
{ get_common_unit(get_unit(r1), get_unit(r2), get_unit(rest)...) } -> Unit;
|
||||
}
|
||||
{
|
||||
return detail::reference_t<common_quantity_spec(get_quantity_spec(R1{}), get_quantity_spec(R2{}),
|
||||
get_quantity_spec(rest)...),
|
||||
common_unit(get_unit(R1{}), get_unit(R2{}), get_unit(rest)...)>{};
|
||||
return detail::reference_t<get_common_quantity_spec(get_quantity_spec(R1{}), get_quantity_spec(R2{}),
|
||||
get_quantity_spec(rest)...),
|
||||
get_common_unit(get_unit(R1{}), get_unit(R2{}), get_unit(rest)...)>{};
|
||||
}
|
||||
|
||||
MP_UNITS_EXPORT_END
|
||||
|
||||
@@ -623,11 +623,11 @@ template<Unit From, Unit To>
|
||||
}
|
||||
|
||||
// Common unit
|
||||
[[nodiscard]] consteval Unit auto common_unit(Unit auto u) { return u; }
|
||||
[[nodiscard]] consteval Unit auto get_common_unit(Unit auto u) { return u; }
|
||||
|
||||
template<Unit U1, Unit U2>
|
||||
requires(convertible(U1{}, U2{}))
|
||||
[[nodiscard]] consteval Unit auto common_unit(U1 u1, U2 u2)
|
||||
[[nodiscard]] consteval Unit auto get_common_unit(U1 u1, U2 u2)
|
||||
{
|
||||
if constexpr (is_same_v<U1, U2>)
|
||||
return u1;
|
||||
@@ -654,10 +654,10 @@ template<Unit U1, Unit U2>
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] consteval Unit auto common_unit(Unit auto u1, Unit auto u2, Unit auto u3, Unit auto... rest)
|
||||
requires requires { common_unit(common_unit(u1, u2), u3, rest...); }
|
||||
[[nodiscard]] consteval Unit auto get_common_unit(Unit auto u1, Unit auto u2, Unit auto u3, Unit auto... rest)
|
||||
requires requires { get_common_unit(get_common_unit(u1, u2), u3, rest...); }
|
||||
{
|
||||
return common_unit(common_unit(u1, u2), u3, rest...);
|
||||
return get_common_unit(get_common_unit(u1, u2), u3, rest...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -228,11 +228,11 @@ template<auto R, auto PO, typename Rep>
|
||||
* @return Quantity: The nearest floating point representable to ax+b
|
||||
*/
|
||||
template<auto R, auto S, auto T, typename Rep1, typename Rep2, typename Rep3>
|
||||
requires requires { common_quantity_spec(get_quantity_spec(R) * get_quantity_spec(S), get_quantity_spec(T)); } &&
|
||||
requires requires { get_common_quantity_spec(get_quantity_spec(R) * get_quantity_spec(S), get_quantity_spec(T)); } &&
|
||||
(get_unit(R) * get_unit(S) == get_unit(T)) && requires(Rep1 v1, Rep2 v2, Rep3 v3) {
|
||||
requires requires { fma(v1, v2, v3); } || requires { std::fma(v1, v2, v3); };
|
||||
}
|
||||
[[nodiscard]] constexpr QuantityOf<common_quantity_spec(
|
||||
[[nodiscard]] constexpr QuantityOf<get_common_quantity_spec(
|
||||
get_quantity_spec(R) * get_quantity_spec(S), get_quantity_spec(T))> auto fma(const quantity<R, Rep1>& a,
|
||||
const quantity<S, Rep2>& x,
|
||||
const quantity<T, Rep3>& b) noexcept
|
||||
@@ -240,7 +240,7 @@ template<auto R, auto S, auto T, typename Rep1, typename Rep2, typename Rep3>
|
||||
using std::fma;
|
||||
return quantity{
|
||||
fma(a.numerical_value_ref_in(a.unit), x.numerical_value_ref_in(x.unit), b.numerical_value_ref_in(b.unit)),
|
||||
common_reference(R * S, T)};
|
||||
get_common_reference(R * S, T)};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,19 +252,19 @@ template<auto R, auto S, auto T, typename Rep1, typename Rep2, typename Rep3>
|
||||
* @return QuantityPoint: The nearest floating point representable to ax+b
|
||||
*/
|
||||
template<auto R, auto S, auto T, auto Origin, typename Rep1, typename Rep2, typename Rep3>
|
||||
requires requires { common_quantity_spec(get_quantity_spec(R) * get_quantity_spec(S), get_quantity_spec(T)); } &&
|
||||
requires requires { get_common_quantity_spec(get_quantity_spec(R) * get_quantity_spec(S), get_quantity_spec(T)); } &&
|
||||
(get_unit(R) * get_unit(S) == get_unit(T)) && requires(Rep1 v1, Rep2 v2, Rep3 v3) {
|
||||
requires requires { fma(v1, v2, v3); } || requires { std::fma(v1, v2, v3); };
|
||||
}
|
||||
[[nodiscard]] constexpr QuantityPointOf<
|
||||
common_quantity_spec(get_quantity_spec(R) * get_quantity_spec(S),
|
||||
get_quantity_spec(T))> auto fma(const quantity<R, Rep1>& a, const quantity<S, Rep2>& x,
|
||||
const quantity_point<T, Origin, Rep3>& b) noexcept
|
||||
get_common_quantity_spec(get_quantity_spec(R) * get_quantity_spec(S),
|
||||
get_quantity_spec(T))> auto fma(const quantity<R, Rep1>& a, const quantity<S, Rep2>& x,
|
||||
const quantity_point<T, Origin, Rep3>& b) noexcept
|
||||
{
|
||||
using std::fma;
|
||||
return Origin + quantity{fma(a.numerical_value_ref_in(a.unit), x.numerical_value_ref_in(x.unit),
|
||||
b.quantity_ref_from(b.point_origin).numerical_value_ref_in(b.unit)),
|
||||
common_reference(R * S, T)};
|
||||
get_common_reference(R * S, T)};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,13 +272,13 @@ template<auto R, auto S, auto T, auto Origin, typename Rep1, typename Rep2, type
|
||||
*/
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
requires requires(Rep1 v1, Rep2 v2) {
|
||||
common_reference(R1, R2);
|
||||
get_common_reference(R1, R2);
|
||||
requires requires { fmod(v1, v2); } || requires { std::fmod(v1, v2); };
|
||||
}
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(R1)> auto fmod(const quantity<R1, Rep1>& x,
|
||||
const quantity<R2, Rep2>& y) noexcept
|
||||
{
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto ref = get_common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::fmod;
|
||||
return quantity{fmod(x.numerical_value_in(unit), y.numerical_value_in(unit)), ref};
|
||||
@@ -289,13 +289,13 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
*/
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
requires requires(Rep1 v1, Rep2 v2) {
|
||||
common_reference(R1, R2);
|
||||
get_common_reference(R1, R2);
|
||||
requires requires { remainder(v1, v2); } || requires { std::remainder(v1, v2); };
|
||||
}
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(R1)> auto remainder(const quantity<R1, Rep1>& x,
|
||||
const quantity<R2, Rep2>& y) noexcept
|
||||
{
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto ref = get_common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::remainder;
|
||||
return quantity{remainder(x.numerical_value_in(unit), y.numerical_value_in(unit)), ref};
|
||||
@@ -451,13 +451,13 @@ template<Unit auto To, auto R, typename Rep>
|
||||
*/
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
requires requires(Rep1 v1, Rep2 v2) {
|
||||
common_reference(R1, R2);
|
||||
get_common_reference(R1, R2);
|
||||
requires requires { hypot(v1, v2); } || requires { std::hypot(v1, v2); };
|
||||
}
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(common_reference(R1, R2))> auto hypot(
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(get_common_reference(R1, R2))> auto hypot(
|
||||
const quantity<R1, Rep1>& x, const quantity<R2, Rep2>& y) noexcept
|
||||
{
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto ref = get_common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::hypot;
|
||||
return quantity{hypot(x.numerical_value_in(unit), y.numerical_value_in(unit)), ref};
|
||||
@@ -469,13 +469,13 @@ template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
*/
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2, auto R3, typename Rep3>
|
||||
requires requires(Rep1 v1, Rep2 v2, Rep3 v3) {
|
||||
common_reference(R1, R2, R3);
|
||||
get_common_reference(R1, R2, R3);
|
||||
requires requires { hypot(v1, v2, v3); } || requires { std::hypot(v1, v2, v3); };
|
||||
}
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(common_reference(R1, R2, R3))> auto hypot(
|
||||
[[nodiscard]] constexpr QuantityOf<get_quantity_spec(get_common_reference(R1, R2, R3))> auto hypot(
|
||||
const quantity<R1, Rep1>& x, const quantity<R2, Rep2>& y, const quantity<R3, Rep3>& z) noexcept
|
||||
{
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto ref = get_common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::hypot;
|
||||
return quantity{hypot(x.numerical_value_in(unit), y.numerical_value_in(unit), z.numerical_value_in(unit)), ref};
|
||||
|
||||
@@ -129,12 +129,12 @@ template<ReferenceOf<dimensionless> auto R, typename Rep>
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
requires requires(Rep1 v1, Rep2 v2) {
|
||||
common_reference(R1, R2);
|
||||
get_common_reference(R1, R2);
|
||||
requires requires { atan2(v1, v2); } || requires { std::atan2(v1, v2); };
|
||||
}
|
||||
[[nodiscard]] inline QuantityOf<angle> auto atan2(const quantity<R1, Rep1>& y, const quantity<R2, Rep2>& x) noexcept
|
||||
{
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto ref = get_common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::atan2;
|
||||
if constexpr (!treat_as_floating_point<Rep1> || !treat_as_floating_point<Rep2>) {
|
||||
|
||||
@@ -132,13 +132,13 @@ template<ReferenceOf<dimensionless> auto R, typename Rep>
|
||||
|
||||
template<auto R1, typename Rep1, auto R2, typename Rep2>
|
||||
requires requires(Rep1 v1, Rep2 v2) {
|
||||
common_reference(R1, R2);
|
||||
get_common_reference(R1, R2);
|
||||
requires requires { atan2(v1, v2); } || requires { std::atan2(v1, v2); };
|
||||
}
|
||||
[[nodiscard]] inline QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::angular_measure)> auto atan2(
|
||||
const quantity<R1, Rep1>& y, const quantity<R2, Rep2>& x) noexcept
|
||||
{
|
||||
constexpr auto ref = common_reference(R1, R2);
|
||||
constexpr auto ref = get_common_reference(R1, R2);
|
||||
constexpr auto unit = get_unit(ref);
|
||||
using std::atan2;
|
||||
if constexpr (!treat_as_floating_point<Rep1> || !treat_as_floating_point<Rep2>) {
|
||||
|
||||
Reference in new issue
Block a user