style: formatting to make pre-commit happy

This commit is contained in:
Mateusz Pusz
2023-08-25 23:05:36 +02:00
parent f7bd67bf09
commit f29c57d367
7 changed files with 86 additions and 97 deletions

View File

@ -45,7 +45,8 @@ std::vector<distance> task::make_leg_total_distances(const legs& legs)
std::vector<distance> res; std::vector<distance> res;
res.reserve(legs.size()); res.reserve(legs.size());
auto to_length = [](const leg& l) { return l.get_distance(); }; auto to_length = [](const leg& l) { return l.get_distance(); };
std::transform_inclusive_scan(legs.cbegin(), legs.cend(), std::back_inserter(res), std::plus(), to_length, distance::zero()); std::transform_inclusive_scan(legs.cbegin(), legs.cend(), std::back_inserter(res), std::plus(), to_length,
distance::zero());
return res; return res;
} }

View File

@ -107,8 +107,8 @@ concept Magnitude = detail::is_magnitude<T>;
/** /**
* @brief A basis vector in our magnitude representation, raised to some rational power. * @brief A basis vector in our magnitude representation, raised to some rational power.
* *
* The public API is that there is a `power` member variable (of type `ratio`), and a `get_base_value()` member function (of * The public API is that there is a `power` member variable (of type `ratio`), and a `get_base_value()` member function
* type either `std::intmax_t` or `long double`, as appropriate), for any specialization. * (of type either `std::intmax_t` or `long double`, as appropriate), for any specialization.
* *
* These types exist to be used as NTTPs for the variadic `magnitude<...>` template. We represent a magnitude (which is * These types exist to be used as NTTPs for the variadic `magnitude<...>` template. We represent a magnitude (which is
* a positive real number) as the product of rational powers of "basis vectors", where each "basis vector" is a positive * a positive real number) as the product of rational powers of "basis vectors", where each "basis vector" is a positive
@ -184,7 +184,8 @@ namespace detail {
template<MagnitudeSpec Element> template<MagnitudeSpec Element>
[[nodiscard]] consteval auto get_base(Element element) [[nodiscard]] consteval auto get_base(Element element)
{ {
if constexpr (detail::is_specialization_of_power_v<Element>) return Element::base; if constexpr (detail::is_specialization_of_power_v<Element>)
return Element::base;
else else
return element; return element;
} }
@ -394,8 +395,8 @@ namespace detail {
// // and/or iterations. We can still _perform_ the factorization for these by using the `known_first_factor` // // and/or iterations. We can still _perform_ the factorization for these by using the `known_first_factor`
// // workaround. However, we can't _check_ that they are prime, because this workaround depends on the input being // // workaround. However, we can't _check_ that they are prime, because this workaround depends on the input being
// // usable in a constexpr expression. This is true for `prime_factorization` (below), where the input `N` is a // // usable in a constexpr expression. This is true for `prime_factorization` (below), where the input `N` is a
// // template parameter, but is not true for our case, where the input `bp.get_base_value()` is a function parameter. // // template parameter, but is not true for our case, where the input `bp.get_base_value()` is a function
// (See // parameter. (See
// // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1045r1.html for some background reading on this // // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1045r1.html for some background reading on this
// // distinction.) // // distinction.)
// // // //

View File

@ -141,7 +141,8 @@ template<basic_symbol_text Symbol, Magnitude auto M, PrefixableUnit auto U>
inline constexpr bool is_specialization_of_prefixed_unit<prefixed_unit<Symbol, M, U>> = true; inline constexpr bool is_specialization_of_prefixed_unit<prefixed_unit<Symbol, M, U>> = true;
template<typename T> template<typename T>
requires requires(T* t) { is_unit_impl(t); } && (!is_specialization_of_named_unit<T>) && (!is_specialization_of_prefixed_unit<T>) requires requires(T* t) { is_unit_impl(t); } && (!is_specialization_of_named_unit<T>) &&
(!is_specialization_of_prefixed_unit<T>)
struct is_unit<T> : std::true_type {}; struct is_unit<T> : std::true_type {};
template<Unit U> template<Unit U>

View File

@ -415,23 +415,20 @@ TEST_CASE("unknown unit modifiers should throw", "[text][fmt][exception]")
SECTION("invalid modifier in the front") SECTION("invalid modifier in the front")
{ {
REQUIRE_THROWS_MATCHES( REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%xUdaq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::vformat("{:%xUdaq}", MP_UNITS_STD_FMT::make_format_args(q)), MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified"));
MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified"));
} }
SECTION("invalid modifier in the end") SECTION("invalid modifier in the end")
{ {
REQUIRE_THROWS_MATCHES( REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%Udaxq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::vformat("{:%Udaxq}", MP_UNITS_STD_FMT::make_format_args(q)), MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified"));
MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified"));
} }
SECTION("invalid modifier in the middle") SECTION("invalid modifier in the middle")
{ {
REQUIRE_THROWS_MATCHES( REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%Udxaq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::vformat("{:%Udxaq}", MP_UNITS_STD_FMT::make_format_args(q)), MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified"));
MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("invalid unit modifier specified"));
} }
} }
@ -441,50 +438,41 @@ TEST_CASE("repeated unit modifiers should throw", "[text][fmt][exception]")
SECTION("text encoding") SECTION("text encoding")
{ {
REQUIRE_THROWS_MATCHES( REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%UdaUq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::vformat("{:%UdaUq}", MP_UNITS_STD_FMT::make_format_args(q)), MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec"));
Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dUaUq}", MP_UNITS_STD_FMT::make_format_args(q)),
REQUIRE_THROWS_MATCHES( MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::vformat("{:%dUaUq}", MP_UNITS_STD_FMT::make_format_args(q)), Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::format_error, REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dUUaq}", MP_UNITS_STD_FMT::make_format_args(q)),
Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); MP_UNITS_STD_FMT::format_error,
REQUIRE_THROWS_MATCHES( Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::vformat("{:%dUUaq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::format_error,
Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec"));
} }
SECTION("solidus") SECTION("solidus")
{ {
REQUIRE_THROWS_MATCHES( REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%aUdaq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::vformat("{:%aUdaq}", MP_UNITS_STD_FMT::make_format_args(q)), MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec"));
Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%daUaq}", MP_UNITS_STD_FMT::make_format_args(q)),
REQUIRE_THROWS_MATCHES( MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::vformat("{:%daUaq}", MP_UNITS_STD_FMT::make_format_args(q)), Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::format_error, REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%daaUq}", MP_UNITS_STD_FMT::make_format_args(q)),
Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); MP_UNITS_STD_FMT::format_error,
REQUIRE_THROWS_MATCHES( Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::vformat("{:%daaUq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::format_error,
Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec"));
} }
SECTION("separator") SECTION("separator")
{ {
REQUIRE_THROWS_MATCHES( REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dUadq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::vformat("{:%dUadq}", MP_UNITS_STD_FMT::make_format_args(q)), MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec"));
Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dadUq}", MP_UNITS_STD_FMT::make_format_args(q)),
REQUIRE_THROWS_MATCHES( MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::vformat("{:%dadUq}", MP_UNITS_STD_FMT::make_format_args(q)), Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::format_error, REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%addUq}", MP_UNITS_STD_FMT::make_format_args(q)),
Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); MP_UNITS_STD_FMT::format_error,
REQUIRE_THROWS_MATCHES( Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::vformat("{:%addUq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::format_error,
Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec"));
} }
} }
@ -494,50 +482,41 @@ TEST_CASE("more then one modifier of the same kind should throw", "[text][fmt][e
SECTION("text encoding") SECTION("text encoding")
{ {
REQUIRE_THROWS_MATCHES( REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%UdaAq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::vformat("{:%UdaAq}", MP_UNITS_STD_FMT::make_format_args(q)), MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec"));
Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dAaUq}", MP_UNITS_STD_FMT::make_format_args(q)),
REQUIRE_THROWS_MATCHES( MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::vformat("{:%dAaUq}", MP_UNITS_STD_FMT::make_format_args(q)), Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::format_error, REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dAUaq}", MP_UNITS_STD_FMT::make_format_args(q)),
Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec")); MP_UNITS_STD_FMT::format_error,
REQUIRE_THROWS_MATCHES( Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::vformat("{:%dAUaq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::format_error,
Catch::Matchers::Message("only one of 'UA' unit modifiers may be used in the format spec"));
} }
SECTION("solidus") SECTION("solidus")
{ {
REQUIRE_THROWS_MATCHES( REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%aUdnq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::vformat("{:%aUdnq}", MP_UNITS_STD_FMT::make_format_args(q)), MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec"));
Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dnUaq}", MP_UNITS_STD_FMT::make_format_args(q)),
REQUIRE_THROWS_MATCHES( MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::vformat("{:%dnUaq}", MP_UNITS_STD_FMT::make_format_args(q)), Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::format_error, REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%daoUq}", MP_UNITS_STD_FMT::make_format_args(q)),
Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec")); MP_UNITS_STD_FMT::format_error,
REQUIRE_THROWS_MATCHES( Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::vformat("{:%daoUq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::format_error,
Catch::Matchers::Message("only one of 'oan' unit modifiers may be used in the format spec"));
} }
SECTION("separator") SECTION("separator")
{ {
REQUIRE_THROWS_MATCHES( REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%dUasq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::vformat("{:%dUasq}", MP_UNITS_STD_FMT::make_format_args(q)), MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec"));
Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%sadUq}", MP_UNITS_STD_FMT::make_format_args(q)),
REQUIRE_THROWS_MATCHES( MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::vformat("{:%sadUq}", MP_UNITS_STD_FMT::make_format_args(q)), Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::format_error, REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%adsUq}", MP_UNITS_STD_FMT::make_format_args(q)),
Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec")); MP_UNITS_STD_FMT::format_error,
REQUIRE_THROWS_MATCHES( Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec"));
MP_UNITS_STD_FMT::vformat("{:%adsUq}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::format_error,
Catch::Matchers::Message("only one of 'sd' unit modifiers may be used in the format spec"));
} }
} }
@ -704,10 +683,9 @@ TEST_CASE("precision specification for integral representation should throw", "[
SECTION("full format {:%Q %q} on a quantity") SECTION("full format {:%Q %q} on a quantity")
{ {
REQUIRE_THROWS_MATCHES( REQUIRE_THROWS_MATCHES(MP_UNITS_STD_FMT::vformat("{:%.1Q %q}", MP_UNITS_STD_FMT::make_format_args(q)),
MP_UNITS_STD_FMT::vformat("{:%.1Q %q}", MP_UNITS_STD_FMT::make_format_args(q)), MP_UNITS_STD_FMT::format_error,
MP_UNITS_STD_FMT::format_error, Catch::Matchers::Message("precision not allowed for integral quantity representation"));
Catch::Matchers::Message("precision not allowed for integral quantity representation"));
} }
SECTION("value only format {:%Q} on a quantity") SECTION("value only format {:%Q} on a quantity")

View File

@ -63,7 +63,8 @@ static_assert(1 * isq::length[nmi] == 1852 * isq::length[si::metre]);
static_assert(1 * isq::speed[kn] == isq::length(1 * nmi) / isq::time(1 * si::hour)); static_assert(1 * isq::speed[kn] == isq::length(1 * nmi) / isq::time(1 * si::hour));
// Force // Force
static_assert(1 * isq::force[pdl] == isq::mass(1 * lb) * isq::length(1 * ft) / (isq::time(1 * si::second) * isq::time(1 * si::second))); static_assert(1 * isq::force[pdl] ==
isq::mass(1 * lb) * isq::length(1 * ft) / (isq::time(1 * si::second) * isq::time(1 * si::second)));
static_assert(1 * isq::force[lbf] == isq::mass(1 * lb) * (1 * si::standard_gravity)); static_assert(1 * isq::force[lbf] == isq::mass(1 * lb) * (1 * si::standard_gravity));
static_assert(1 * isq::force[kip] == 1000 * isq::force[lbf]); static_assert(1 * isq::force[kip] == 1000 * isq::force[lbf]);

View File

@ -33,7 +33,8 @@ using namespace mp_units;
using namespace mp_units::natural::unit_symbols; using namespace mp_units::natural::unit_symbols;
static_assert(1 * natural::length[1 / GeV] / (1 * natural::time[1 / GeV]) == 1 * natural::speed[one]); static_assert(1 * natural::length[1 / GeV] / (1 * natural::time[1 / GeV]) == 1 * natural::speed[one]);
static_assert(1 * natural::length[1 / GeV] / (1 * natural::time[1 / GeV] * (1 * natural::time[1 / GeV])) == 1 * natural::acceleration[GeV]); static_assert(1 * natural::length[1 / GeV] / (1 * natural::time[1 / GeV] * (1 * natural::time[1 / GeV])) ==
1 * natural::acceleration[GeV]);
static_assert(1 * natural::mass[GeV] * (1 * natural::velocity[one]) == 1 * natural::momentum[GeV]); static_assert(1 * natural::mass[GeV] * (1 * natural::velocity[one]) == 1 * natural::momentum[GeV]);
static_assert(1 * natural::mass[GeV] * (1 * natural::acceleration[GeV]) == 1 * natural::force[GeV2]); static_assert(1 * natural::mass[GeV] * (1 * natural::acceleration[GeV]) == 1 * natural::force[GeV2]);
static_assert(1 * natural::mass[GeV] * (1 * natural::acceleration[GeV]) * (1 * natural::length[1 / GeV]) == static_assert(1 * natural::mass[GeV] * (1 * natural::acceleration[GeV]) * (1 * natural::length[1 / GeV]) ==

View File

@ -693,7 +693,9 @@ static_assert(invalid_compound_assignments<quantity_point>);
template<template<auto, auto, typename> typename QP, auto Origin, auto OtherOrigin> template<template<auto, auto, typename> typename QP, auto Origin, auto OtherOrigin>
concept invalid_binary_operations = requires { concept invalid_binary_operations = requires {
// can't add two quantity points // can't add two quantity points
requires !requires { QP<isq::height[m], mean_sea_level, int>(1 * m) + QP<isq::height[m], mean_sea_level, int>(1 * m); }; requires !requires {
QP<isq::height[m], mean_sea_level, int>(1 * m) + QP<isq::height[m], mean_sea_level, int>(1 * m);
};
requires !requires { mean_sea_level + QP<isq::height[m], mean_sea_level, int>(1 * m); }; requires !requires { mean_sea_level + QP<isq::height[m], mean_sea_level, int>(1 * m); };
requires !requires { QP<isq::height[m], mean_sea_level, int>(1 * m) + mean_sea_level; }; requires !requires { QP<isq::height[m], mean_sea_level, int>(1 * m) + mean_sea_level; };
requires !requires { Origin + Origin; }; requires !requires { Origin + Origin; };
@ -722,8 +724,12 @@ concept invalid_binary_operations = requires {
requires !requires { Origin - 1 * s; }; requires !requires { Origin - 1 * s; };
// can't subtract two quantity points of incompatible origins // can't subtract two quantity points of incompatible origins
requires !requires { QP<isq::height[m], mean_sea_level, int>(1 * m) - QP<isq::height[m], other_absolute_level, int>(1 * m); }; requires !requires {
requires !requires { QP<isq::height[m], other_absolute_level, int>(1 * m) - QP<isq::height[m], mean_sea_level, int>(1 * m); }; QP<isq::height[m], mean_sea_level, int>(1 * m) - QP<isq::height[m], other_absolute_level, int>(1 * m);
};
requires !requires {
QP<isq::height[m], other_absolute_level, int>(1 * m) - QP<isq::height[m], mean_sea_level, int>(1 * m);
};
requires !requires { mean_sea_level - QP<isq::height[m], other_absolute_level, int>(1 * m); }; requires !requires { mean_sea_level - QP<isq::height[m], other_absolute_level, int>(1 * m); };
requires !requires { QP<isq::height[m], mean_sea_level, int>(1 * m) - other_absolute_level; }; requires !requires { QP<isq::height[m], mean_sea_level, int>(1 * m) - other_absolute_level; };