refactor: code refactored to comply with clang-tidy
This commit is contained in:
1 parent
901b5e5394
commit
75f719add7
46 files changed
+489
-380
No files matched your search
@@ -0,0 +1,6 @@
|
||||
Checks: '
|
||||
-bugprone-exception-escape,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-google-build-using-namespace
|
||||
'
|
||||
InheritParentConfig: true
|
||||
@@ -35,7 +35,7 @@ namespace {
|
||||
|
||||
template<mp_units::Quantity Target, mp_units::Quantity Source>
|
||||
requires std::constructible_from<Target, Source>
|
||||
inline constexpr double conversion_factor(Target, Source)
|
||||
constexpr double conversion_factor(Target, Source)
|
||||
{
|
||||
return (1. * Source::reference).force_numerical_value_in(Target::unit);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ inline constexpr auto JPY = japanese_jen;
|
||||
static_assert(!std::equality_comparable_with<quantity<euro, int>, quantity<us_dollar, int>>);
|
||||
|
||||
|
||||
#if 0
|
||||
#if 0 // NOLINT(readability-avoid-unconditional-preprocessor-if)
|
||||
|
||||
// if you have only a few currencies to handle
|
||||
template<Unit auto From, Unit auto To>
|
||||
@@ -76,12 +76,12 @@ template<Unit auto From, Unit auto To>
|
||||
template<Unit auto From, Unit auto To>
|
||||
[[nodiscard]] double exchange_rate()
|
||||
{
|
||||
static std::map<std::pair<std::string_view, std::string_view>, double> rates = {
|
||||
static const std::map<std::pair<std::string_view, std::string_view>, double> rates = {
|
||||
{{"USD", "EUR"}, 0.9215}, {{"EUR", "USD"}, 1.0848},
|
||||
// ...
|
||||
};
|
||||
|
||||
return rates[std::make_pair(to_string_view(From), to_string_view(To))];
|
||||
return rates.at(std::make_pair(to_string_view(From), to_string_view(To)));
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -103,8 +103,8 @@ int main()
|
||||
{
|
||||
using namespace unit_symbols;
|
||||
|
||||
quantity_point price_usd{100 * USD};
|
||||
quantity_point price_euro = exchange_to<euro>(price_usd);
|
||||
const quantity_point price_usd{100 * USD};
|
||||
const quantity_point price_euro = exchange_to<euro>(price_usd);
|
||||
|
||||
std::cout << price_usd.quantity_from_zero() << " -> " << price_euro.quantity_from_zero() << "\n";
|
||||
// std::cout << price_usd.quantity_from_zero() + price_euro.quantity_from_zero() << "\n"; // does
|
||||
|
||||
@@ -181,7 +181,7 @@ void example()
|
||||
|
||||
for (const auto& g : gliders) {
|
||||
for (const auto& c : weather_conditions) {
|
||||
std::string txt = "Scenario: Glider = " + g.name + ", Weather = " + c.first;
|
||||
const std::string txt = "Scenario: Glider = " + g.name + ", Weather = " + c.first;
|
||||
std::cout << txt << "\n";
|
||||
std::cout << MP_UNITS_STD_FMT::format("{0:=^{1}}\n\n", "", txt.size());
|
||||
|
||||
|
||||
@@ -111,10 +111,11 @@ public:
|
||||
const waypoint* end_;
|
||||
distance length_ = geographic::spherical_distance(begin().pos, end().pos);
|
||||
public:
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
leg(const waypoint& b, const waypoint& e) noexcept : begin_(&b), end_(&e) {}
|
||||
constexpr const waypoint& begin() const { return *begin_; };
|
||||
constexpr const waypoint& end() const { return *end_; }
|
||||
constexpr distance get_distance() const { return length_; }
|
||||
[[nodiscard]] constexpr const waypoint& begin() const { return *begin_; };
|
||||
[[nodiscard]] constexpr const waypoint& end() const { return *end_; }
|
||||
[[nodiscard]] constexpr distance get_distance() const { return length_; }
|
||||
};
|
||||
using legs = std::vector<leg>;
|
||||
|
||||
@@ -126,19 +127,19 @@ public:
|
||||
|
||||
task(std::initializer_list<waypoint> wpts) : waypoints_(wpts) {}
|
||||
|
||||
const waypoints& get_waypoints() const { return waypoints_; }
|
||||
const legs& get_legs() const { return legs_; }
|
||||
[[nodiscard]] const waypoints& get_waypoints() const { return waypoints_; }
|
||||
[[nodiscard]] const legs& get_legs() const { return legs_; }
|
||||
|
||||
const waypoint& get_start() const { return waypoints_.front(); }
|
||||
const waypoint& get_finish() const { return waypoints_.back(); }
|
||||
[[nodiscard]] const waypoint& get_start() const { return waypoints_.front(); }
|
||||
[[nodiscard]] const waypoint& get_finish() const { return waypoints_.back(); }
|
||||
|
||||
distance get_distance() const { return length_; }
|
||||
[[nodiscard]] distance get_distance() const { return length_; }
|
||||
|
||||
distance get_leg_dist_offset(std::size_t leg_index) const
|
||||
[[nodiscard]] distance get_leg_dist_offset(std::size_t leg_index) const
|
||||
{
|
||||
return leg_index == 0 ? distance{} : leg_total_distances_[leg_index - 1];
|
||||
}
|
||||
std::size_t get_leg_index(distance dist) const
|
||||
[[nodiscard]] std::size_t get_leg_index(distance dist) const
|
||||
{
|
||||
return static_cast<std::size_t>(
|
||||
std::ranges::distance(leg_total_distances_.cbegin(), std::ranges::lower_bound(leg_total_distances_, dist)));
|
||||
|
||||
@@ -84,20 +84,14 @@ template<class CharT, class Traits, typename T>
|
||||
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const latitude<T>& lat)
|
||||
{
|
||||
const auto& q = lat.quantity_ref_from(geographic::equator);
|
||||
if (is_gteq_zero(q))
|
||||
return os << q << " N";
|
||||
else
|
||||
return os << -q << " S";
|
||||
return (is_gteq_zero(q)) ? (os << q << " N") : (os << -q << " S");
|
||||
}
|
||||
|
||||
template<class CharT, class Traits, typename T>
|
||||
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const longitude<T>& lon)
|
||||
{
|
||||
const auto& q = lon.quantity_ref_from(geographic::prime_meridian);
|
||||
if (is_gteq_zero(q))
|
||||
return os << q << " E";
|
||||
else
|
||||
return os << -q << " W";
|
||||
return (is_gteq_zero(q)) ? (os << q << " E") : (os << -q << " W");
|
||||
}
|
||||
|
||||
inline namespace literals {
|
||||
@@ -174,6 +168,7 @@ struct position {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
distance spherical_distance(position<T> from, position<T> to)
|
||||
{
|
||||
using namespace mp_units;
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
import mp_units.core;
|
||||
#else
|
||||
#include <mp-units/bits/fmt.h>
|
||||
#include <mp-units/bits/hacks.h>
|
||||
#include <mp-units/framework/customization_points.h>
|
||||
#endif
|
||||
|
||||
@@ -82,12 +81,14 @@ public:
|
||||
|
||||
#else
|
||||
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
constexpr explicit(false) operator T() const& noexcept(std::is_nothrow_copy_constructible_v<T>)
|
||||
requires std::copyable<T>
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
constexpr explicit(false) operator T() && noexcept(std::is_nothrow_move_constructible_v<T>)
|
||||
{
|
||||
return std::move(value_);
|
||||
@@ -96,14 +97,14 @@ public:
|
||||
#endif
|
||||
|
||||
constexpr T& value() & noexcept = delete;
|
||||
constexpr const T& value() const& noexcept { return value_; }
|
||||
constexpr T&& value() && noexcept { return std::move(value_); }
|
||||
constexpr const T&& value() const&& noexcept { return std::move(value_); }
|
||||
[[nodiscard]] constexpr const T& value() const& noexcept { return value_; }
|
||||
[[nodiscard]] constexpr T&& value() && noexcept { return std::move(value_); }
|
||||
[[nodiscard]] constexpr const T&& value() const&& noexcept { return std::move(value_); }
|
||||
|
||||
bool operator==(const validated_type&) const
|
||||
[[nodiscard]] bool operator==(const validated_type&) const
|
||||
requires std::equality_comparable<T>
|
||||
= default;
|
||||
auto operator<=>(const validated_type&) const
|
||||
[[nodiscard]] auto operator<=>(const validated_type&) const
|
||||
requires std::three_way_comparable<T>
|
||||
= default;
|
||||
};
|
||||
|
||||
@@ -45,11 +45,13 @@ public:
|
||||
|
||||
measurement() = default;
|
||||
|
||||
constexpr explicit measurement(value_type val, const value_type& err = {}) : value_(std::move(val))
|
||||
// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
|
||||
constexpr explicit measurement(value_type val, const value_type& err = {}) :
|
||||
value_(std::move(val)), uncertainty_([&] {
|
||||
using namespace std;
|
||||
return abs(err);
|
||||
}())
|
||||
{
|
||||
// it sucks that using declaration cannot be provided for a constructor initializer list
|
||||
using namespace std;
|
||||
uncertainty_ = abs(err);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const value_type& value() const { return value_; }
|
||||
|
||||
@@ -40,8 +40,6 @@ using namespace mp_units;
|
||||
using mp_units::si::unit_symbols::cm;
|
||||
using mp_units::si::unit_symbols::eV;
|
||||
using mp_units::si::unit_symbols::K;
|
||||
using mp_units::si::unit_symbols::kJ;
|
||||
using mp_units::si::unit_symbols::mol;
|
||||
using mp_units::si::unit_symbols::THz;
|
||||
using mp_units::si::unit_symbols::um;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ void si_example()
|
||||
using namespace mp_units::si::unit_symbols;
|
||||
constexpr Unit auto GeV = si::giga<si::electronvolt>;
|
||||
constexpr quantity c = 1. * si::si2019::speed_of_light_in_vacuum;
|
||||
quantity c2 = pow<2>(c);
|
||||
const quantity c2 = pow<2>(c);
|
||||
|
||||
const quantity p1 = isq::momentum(4. * GeV / c);
|
||||
const QuantityOf<isq::mass> auto m1 = 3. * GeV / c2;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ranged_representation.h"
|
||||
#include <mp-units/compat_macros.h>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#ifdef MP_UNITS_MODULES
|
||||
@@ -39,14 +40,14 @@ using namespace geographic;
|
||||
|
||||
// **** HAE ****
|
||||
|
||||
enum class earth_gravity_model { egm84_15, egm95_5, egm2008_1 };
|
||||
enum class earth_gravity_model : std::int8_t { egm84_15, egm95_5, egm2008_1 };
|
||||
|
||||
template<earth_gravity_model M>
|
||||
struct height_above_ellipsoid_t : absolute_point_origin<height_above_ellipsoid_t<M>, isq::altitude> {
|
||||
static constexpr earth_gravity_model egm = M;
|
||||
};
|
||||
template<earth_gravity_model M>
|
||||
inline constexpr height_above_ellipsoid_t<M> height_above_ellipsoid;
|
||||
inline constexpr height_above_ellipsoid_t<M> height_above_ellipsoid; // NOLINT(google-readability-casting)
|
||||
|
||||
template<earth_gravity_model M>
|
||||
using hae_altitude = quantity_point<isq::altitude[si::metre], height_above_ellipsoid<M>>;
|
||||
@@ -141,12 +142,12 @@ class unmanned_aerial_vehicle {
|
||||
msl_altitude launch_ = current_;
|
||||
public:
|
||||
void take_off(msl_altitude alt) { launch_ = alt; }
|
||||
msl_altitude take_off() const { return launch_; }
|
||||
[[nodiscard]] msl_altitude take_off() const { return launch_; }
|
||||
|
||||
void current(msl_altitude alt) { current_ = alt; }
|
||||
msl_altitude current() const { return current_; }
|
||||
[[nodiscard]] msl_altitude current() const { return current_; }
|
||||
|
||||
hal_altitude hal() const { return height_above_launch + (current_ - launch_); }
|
||||
[[nodiscard]] hal_altitude hal() const { return height_above_launch + (current_ - launch_); }
|
||||
};
|
||||
|
||||
|
||||
@@ -160,7 +161,7 @@ int main()
|
||||
uav.current(mean_sea_level + 10'000 * ft);
|
||||
std::cout << MP_UNITS_STD_FMT::format("hal = {::N[.2f]}\n", uav.hal());
|
||||
|
||||
msl_altitude ground_level = mean_sea_level + 123 * m;
|
||||
const msl_altitude ground_level = mean_sea_level + 123 * m;
|
||||
std::cout << MP_UNITS_STD_FMT::format("agl = {::N[.2f]}\n", uav.current() - ground_level);
|
||||
|
||||
struct waypoint {
|
||||
@@ -169,7 +170,7 @@ int main()
|
||||
msl_altitude msl_alt;
|
||||
};
|
||||
|
||||
waypoint wpt = {"EPPR", {54.24772_N, 18.6745_E}, mean_sea_level + 16. * ft};
|
||||
const waypoint wpt = {"EPPR", {54.24772_N, 18.6745_E}, mean_sea_level + 16. * ft};
|
||||
std::cout << MP_UNITS_STD_FMT::format("{}: {} {}, {::N[.2f]}, {::N[.2f]}\n", wpt.name, wpt.pos.lat, wpt.pos.lon,
|
||||
wpt.msl_alt, to_hae<earth_gravity_model::egm2008_1>(wpt.msl_alt, wpt.pos));
|
||||
}
|
||||
Reference in new issue
Block a user