[clang-format]

This commit is contained in:
Jonas Hoppe
2024-09-10 09:58:05 +02:00
parent ee4a7066ca
commit f651438f29
13 changed files with 104 additions and 97 deletions

View File

@@ -49,7 +49,8 @@ struct delta_ {
template<Reference R> template<Reference R>
struct absolute_ { struct absolute_ {
template<typename FwdRep, RepresentationOf<get_quantity_spec(R{}).character> Rep = std::remove_cvref_t<FwdRep>> template<typename FwdRep, RepresentationOf<get_quantity_spec(R{}).character> Rep = std::remove_cvref_t<FwdRep>>
[[nodiscard]] constexpr quantity_point<MP_UNITS_EXPRESSION_WORKAROUND(R{}), default_point_origin(R{}), Rep> operator()(FwdRep&& lhs) const [[nodiscard]] constexpr quantity_point<MP_UNITS_EXPRESSION_WORKAROUND(R{}), default_point_origin(R{}), Rep>
operator()(FwdRep&& lhs) const
{ {
return quantity_point{quantity{std::forward<FwdRep>(lhs), R{}}}; return quantity_point{quantity{std::forward<FwdRep>(lhs), R{}}};
} }

View File

@@ -188,8 +188,7 @@ struct expr_consolidate_impl<type_list<T, T, Rest...>> {
// replaces the instance of a type and a power of it with one with incremented power // replaces the instance of a type and a power of it with one with incremented power
template<typename T, int... Ints, typename... Rest> template<typename T, int... Ints, typename... Rest>
struct expr_consolidate_impl<type_list<T, power<T, Ints...>, Rest...>> { struct expr_consolidate_impl<type_list<T, power<T, Ints...>, Rest...>> {
using type = using type = expr_consolidate_impl<type_list<power_or_T<T, power<T, Ints...>::exponent + 1>, Rest...>>::type;
expr_consolidate_impl<type_list<power_or_T<T, power<T, Ints...>::exponent + 1>, Rest...>>::type;
}; };
// accumulates the powers of instances of the same type (removes the element in case the accumulation result is `0`) // accumulates the powers of instances of the same type (removes the element in case the accumulation result is `0`)

View File

@@ -53,13 +53,15 @@ template<PointOrigin PO>
struct point_origin_interface { struct point_origin_interface {
template<PointOrigin PO, typename FwdQ, QuantityOf<PO::quantity_spec> Q = std::remove_cvref_t<FwdQ>> template<PointOrigin PO, typename FwdQ, QuantityOf<PO::quantity_spec> Q = std::remove_cvref_t<FwdQ>>
[[nodiscard]] friend constexpr quantity_point<Q::reference, MP_UNITS_EXPRESSION_WORKAROUND(PO{}), typename Q::rep> operator+(PO, FwdQ&& q) [[nodiscard]] friend constexpr quantity_point<Q::reference, MP_UNITS_EXPRESSION_WORKAROUND(PO{}), typename Q::rep>
operator+(PO, FwdQ&& q)
{ {
return quantity_point{std::forward<FwdQ>(q), PO{}}; return quantity_point{std::forward<FwdQ>(q), PO{}};
} }
template<Quantity FwdQ, PointOrigin PO, QuantityOf<PO::quantity_spec> Q = std::remove_cvref_t<FwdQ>> template<Quantity FwdQ, PointOrigin PO, QuantityOf<PO::quantity_spec> Q = std::remove_cvref_t<FwdQ>>
[[nodiscard]] friend constexpr quantity_point<Q::reference, MP_UNITS_EXPRESSION_WORKAROUND(PO{}), typename Q::rep> operator+(FwdQ&& q, PO po) [[nodiscard]] friend constexpr quantity_point<Q::reference, MP_UNITS_EXPRESSION_WORKAROUND(PO{}), typename Q::rep>
operator+(FwdQ&& q, PO po)
{ {
return po + std::forward<FwdQ>(q); return po + std::forward<FwdQ>(q);
} }

View File

@@ -667,7 +667,7 @@ template<QuantitySpec Q>
// dimension_one is always the last one // dimension_one is always the last one
// otherwise, sort by typename // otherwise, sort by typename
template<Dimension D1, Dimension D2> template<Dimension D1, Dimension D2>
[[nodiscard]] consteval bool ingredients_dimension_less(D1 lhs, D2 rhs) [[nodiscard]] consteval bool ingredients_dimension_less(D1, D2)
{ {
if constexpr (D1{} == D2{} || D1{} == dimension_one) if constexpr (D1{} == D2{} || D1{} == dimension_one)
return false; return false;
@@ -684,7 +684,7 @@ struct ingredients_less :
std::bool_constant<(lhs_compl > rhs_compl) || std::bool_constant<(lhs_compl > rhs_compl) ||
(lhs_compl == rhs_compl && ingredients_dimension_less(Lhs::dimension, Rhs::dimension)) || (lhs_compl == rhs_compl && ingredients_dimension_less(Lhs::dimension, Rhs::dimension)) ||
(lhs_compl == rhs_compl && Lhs::dimension == Rhs::dimension && (lhs_compl == rhs_compl && Lhs::dimension == Rhs::dimension &&
detail::type_name<Lhs>() < detail::type_name<Rhs>())> {}; detail::type_name<Lhs>() < detail::type_name<Rhs>())>{};
template<typename T1, typename T2> template<typename T1, typename T2>
using type_list_of_ingredients_less = expr_less<T1, T2, ingredients_less>; using type_list_of_ingredients_less = expr_less<T1, T2, ingredients_less>;
@@ -1344,11 +1344,11 @@ template<QuantitySpec From, QuantitySpec To>
get_complexity(From{}) == get_complexity(To{})) get_complexity(From{}) == get_complexity(To{}))
return convertible_impl(from_kind, to_kind); return convertible_impl(from_kind, to_kind);
else if constexpr (get_complexity(From{}) > get_complexity(To{})) else if constexpr (get_complexity(From{}) > get_complexity(To{}))
return exploded_kind_result(convertible_impl( return exploded_kind_result(
get_kind_tree_root(explode<get_complexity(To{})>(from_kind).quantity),to_kind)); convertible_impl(get_kind_tree_root(explode<get_complexity(To{})>(from_kind).quantity), to_kind));
else else
return exploded_kind_result( return exploded_kind_result(
convertible_impl(from_kind,get_kind_tree_root(explode<get_complexity(From{})>(to_kind).quantity))); convertible_impl(from_kind, get_kind_tree_root(explode<get_complexity(From{})>(to_kind).quantity)));
} }
template<NamedQuantitySpec From, NamedQuantitySpec To> template<NamedQuantitySpec From, NamedQuantitySpec To>
@@ -1365,7 +1365,7 @@ template<NamedQuantitySpec From, NamedQuantitySpec To>
return no; return no;
else if constexpr (get_complexity(From{}) != get_complexity(To{})) { else if constexpr (get_complexity(From{}) != get_complexity(To{})) {
if constexpr (get_complexity(From{}) > get_complexity(To{})) if constexpr (get_complexity(From{}) > get_complexity(To{}))
return convertible_impl(explode<get_complexity(To{})>(from).quantity,to); return convertible_impl(explode<get_complexity(To{})>(from).quantity, to);
else { else {
auto res = explode<get_complexity(From{})>(to); auto res = explode<get_complexity(From{})>(to);
return min(res.result, convertible_impl(from, res.quantity)); return min(res.result, convertible_impl(from, res.quantity));

View File

@@ -87,14 +87,15 @@ struct reference {
} }
template<typename Q2, typename U2> template<typename Q2, typename U2>
[[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} * Q2{}), MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> [[nodiscard]] friend consteval detail::reference_t<MP_UNITS_EXPRESSION_WORKAROUND(Q{} * Q2{}),
MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})>
operator*(reference, reference<Q2, U2>) operator*(reference, reference<Q2, U2>)
{ {
return {}; return {};
} }
template<AssociatedUnit U2> template<AssociatedUnit U2>
[[nodiscard]] friend consteval detail::reference_t<( MP_UNITS_EXPRESSION_WORKAROUND(Q{} * get_quantity_spec(U2{}))), [[nodiscard]] friend consteval detail::reference_t<(MP_UNITS_EXPRESSION_WORKAROUND(Q{} * get_quantity_spec(U2{}))),
MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})> MP_UNITS_EXPRESSION_WORKAROUND(U{} * U2{})>
operator*(reference, U2) operator*(reference, U2)
{ {
@@ -102,7 +103,7 @@ struct reference {
} }
template<AssociatedUnit U1> template<AssociatedUnit U1>
[[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) * Q{}), [[nodiscard]] friend consteval detail::reference_t<MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) * Q{}),
MP_UNITS_EXPRESSION_WORKAROUND(U1{} * U{})> MP_UNITS_EXPRESSION_WORKAROUND(U1{} * U{})>
operator*(U1, reference) operator*(U1, reference)
{ {
@@ -110,14 +111,15 @@ struct reference {
} }
template<typename Q2, typename U2> template<typename Q2, typename U2>
[[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} / Q2{}), MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})> [[nodiscard]] friend consteval detail::reference_t<MP_UNITS_EXPRESSION_WORKAROUND(Q{} / Q2{}),
MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})>
operator/(reference, reference<Q2, U2>) operator/(reference, reference<Q2, U2>)
{ {
return {}; return {};
} }
template<AssociatedUnit U2> template<AssociatedUnit U2>
[[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(Q{} / get_quantity_spec(U2{})), [[nodiscard]] friend consteval detail::reference_t<MP_UNITS_EXPRESSION_WORKAROUND(Q{} / get_quantity_spec(U2{})),
MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})> MP_UNITS_EXPRESSION_WORKAROUND(U{} / U2{})>
operator/(reference, U2) operator/(reference, U2)
{ {
@@ -125,7 +127,7 @@ struct reference {
} }
template<AssociatedUnit U1> template<AssociatedUnit U1>
[[nodiscard]] friend consteval detail::reference_t< MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) / Q{}), [[nodiscard]] friend consteval detail::reference_t<MP_UNITS_EXPRESSION_WORKAROUND(get_quantity_spec(U1{}) / Q{}),
MP_UNITS_EXPRESSION_WORKAROUND(U1{} / U{})> MP_UNITS_EXPRESSION_WORKAROUND(U1{} / U{})>
operator/(U1, reference) operator/(U1, reference)
{ {
@@ -291,8 +293,7 @@ template<Reference R1, Reference R2, Reference... Rest>
} -> Unit; } -> Unit;
} }
{ {
return detail::reference_t< return detail::reference_t<common_quantity_spec(get_quantity_spec(R1{}), get_quantity_spec(R2{}),
common_quantity_spec(get_quantity_spec(R1{}), get_quantity_spec(R2{}),
get_quantity_spec(rest)...), get_quantity_spec(rest)...),
common_unit(get_unit(R1{}), get_unit(R2{}), get_unit(rest)...)>{}; common_unit(get_unit(R1{}), get_unit(R2{}), get_unit(rest)...)>{};
} }

View File

@@ -632,7 +632,7 @@ template<Unit From, Unit To>
[[nodiscard]] consteval Unit auto common_unit(Unit auto u) { return u; } [[nodiscard]] consteval Unit auto common_unit(Unit auto u) { return u; }
template<Unit U1, Unit U2> template<Unit U1, Unit U2>
requires(convertible(U1{}, U2{})) requires(convertible(U1{}, U2{}))
[[nodiscard]] consteval Unit auto common_unit(U1 u1, U2 u2) [[nodiscard]] consteval Unit auto common_unit(U1 u1, U2 u2)
{ {
if constexpr (is_same_v<U1, U2>) if constexpr (is_same_v<U1, U2>)

View File

@@ -87,7 +87,8 @@ template<ReferenceOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::angular_measure)> auto R,
template<ReferenceOf<dimensionless> auto R, typename Rep> template<ReferenceOf<dimensionless> auto R, typename Rep>
requires requires(Rep v) { asin(v); } || requires(Rep v) { std::asin(v); } requires requires(Rep v) { asin(v); } || requires(Rep v) { std::asin(v); }
[[nodiscard]] inline QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::angular_measure)> auto asin(const quantity<R, Rep>& q) noexcept [[nodiscard]] inline QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::angular_measure)> auto asin(
const quantity<R, Rep>& q) noexcept
{ {
using std::asin; using std::asin;
if constexpr (!treat_as_floating_point<Rep>) { if constexpr (!treat_as_floating_point<Rep>) {
@@ -101,7 +102,8 @@ template<ReferenceOf<dimensionless> auto R, typename Rep>
template<ReferenceOf<dimensionless> auto R, typename Rep> template<ReferenceOf<dimensionless> auto R, typename Rep>
requires requires(Rep v) { acos(v); } || requires(Rep v) { std::acos(v); } requires requires(Rep v) { acos(v); } || requires(Rep v) { std::acos(v); }
[[nodiscard]] inline QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::angular_measure)> auto acos(const quantity<R, Rep>& q) noexcept [[nodiscard]] inline QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::angular_measure)> auto acos(
const quantity<R, Rep>& q) noexcept
{ {
using std::acos; using std::acos;
if constexpr (!treat_as_floating_point<Rep>) { if constexpr (!treat_as_floating_point<Rep>) {
@@ -115,7 +117,8 @@ template<ReferenceOf<dimensionless> auto R, typename Rep>
template<ReferenceOf<dimensionless> auto R, typename Rep> template<ReferenceOf<dimensionless> auto R, typename Rep>
requires requires(Rep v) { atan(v); } || requires(Rep v) { std::atan(v); } requires requires(Rep v) { atan(v); } || requires(Rep v) { std::atan(v); }
[[nodiscard]] inline QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::angular_measure)> auto atan(const quantity<R, Rep>& q) noexcept [[nodiscard]] inline QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::angular_measure)> auto atan(
const quantity<R, Rep>& q) noexcept
{ {
using std::atan; using std::atan;
if constexpr (!treat_as_floating_point<Rep>) { if constexpr (!treat_as_floating_point<Rep>) {

View File

@@ -20,16 +20,17 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
#include <mp-units/bits/hacks.h>
#include <mp-units/format.h> #include <mp-units/format.h>
#include <mp-units/ostream.h> #include <mp-units/ostream.h>
#include <mp-units/systems/isq.h> #include <mp-units/systems/isq.h>
#include <mp-units/systems/si.h> #include <mp-units/systems/si.h>
#include <mp-units/bits/hacks.h>
#include <iostream> #include <iostream>
using namespace mp_units; using namespace mp_units;
constexpr QuantityOf<isq::speed> auto avg_speed(QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::distance)> auto d, QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::duration)> auto t) constexpr QuantityOf<isq::speed> auto avg_speed(QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::distance)> auto d,
QuantityOf<MP_UNITS_IS_VALUE_WORKAROUND(isq::duration)> auto t)
{ {
return d / t; return d / t;
} }