refactor: IWYU applied to the source files

`alternative_namespaces` examples left out as I consider them a subject for removal in the nearest future.
This commit is contained in:
Mateusz Pusz committed 2021-03-30 13:21:05 +02:00
1 parent 01935996e6
commit 37cfc53d1d
163 files changed
+977 -352

No files matched your search

+7 -2
View File
@@ -20,10 +20,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/isq/si/cgs/speed.h>
#include <units/isq/si/international/speed.h>
#include <units/isq/si/cgs/length.h>
#include <units/isq/si/cgs/speed.h> // IWYU pragma: keep
#include <units/isq/si/international/length.h>
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
#include <units/isq/si/length.h> // IWYU pragma: keep
#include <units/isq/si/time.h>
#include <units/isq/si/speed.h>
#include <units/quantity_io.h>
#include <exception>
#include <iostream>
namespace {
+29 -3
View File
@@ -1,14 +1,40 @@
#include <units/isq/si/constants.h>
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/format.h>
#include <units/generic/dimensionless.h>
#include <units/isq/si/amount_of_substance.h>
#include <units/isq/si/area.h>
#include <units/isq/si/speed.h>
#include <units/isq/si/constants.h>
#include <units/isq/si/density.h>
#include <units/isq/si/force.h>
#include <units/isq/si/length.h>
#include <units/isq/si/mass.h>
#include <units/isq/si/speed.h> // IWYU pragma: keep
#include <units/isq/si/time.h>
#include <units/isq/si/volume.h>
#include <units/format.h>
#include <cassert>
#include <iostream>
#include <utility>
namespace {
+3 -1
View File
@@ -20,11 +20,13 @@
physical_quantities
*/
#include <units/generic/dimensionless.h>
#include <units/isq/dimensions/electric_current.h>
#include <units/isq/si/capacitance.h>
#include <units/isq/si/resistance.h>
#include <units/isq/si/time.h>
#include <units/isq/si/voltage.h>
#include <units/math.h>
#include <units/math.h> // IWYU pragma: keep
#include <units/quantity_io.h>
#include <iostream>
+12 -13
View File
@@ -24,7 +24,6 @@
#include <units/isq/si/time.h>
#include <units/isq/si/typographic/length.h>
#include <units/isq/si/us/length.h>
#include <units/isq/si/volume.h>
#include <units/quantity_io.h>
#include <iostream>
@@ -112,29 +111,29 @@ void calcs_comparison()
"when adding two values of the same very big\n"
"or very small type:\n\n";
length<femtometre,float> L1A = 2._q_fm;
length<femtometre,float> L2A = 3._q_fm;
length<femtometre,float> LrA = L1A + L2A;
fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n",L1A,L2A,LrA);
length<femtometre, float> L1A = 2._q_fm;
length<femtometre, float> L2A = 3._q_fm;
length<femtometre, float> LrA = L1A + L2A;
fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1A, L2A, LrA);
std::cout << "The single unit method must convert large\n"
"or small values in other units to the base unit.\n"
"This is both inefficient and inaccurate\n\n";
length<metre,float> L1B = L1A;
length<metre,float> L2B = L2A;
length<metre,float> LrB = L1B + L2B;
fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n",L1B,L2B,LrB);
length<metre, float> L1B = L1A;
length<metre, float> L2B = L2A;
length<metre, float> LrB = L1B + L2B;
fmt::print("{:%.30Q %q}\n + {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1B, L2B, LrB);
std::cout << "In multiplication and division:\n\n";
area<square_femtometre,float> ArA = L1A * L2A;
fmt::print("{:%.30Q %q}\n * {:%.30Q %q}\n = {:%.30Q %q}\n\n",L1A,L2A,ArA);
area<square_femtometre, float> ArA = L1A * L2A;
fmt::print("{:%.30Q %q}\n * {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1A, L2A, ArA);
std::cout << "similar problems arise\n\n";
area<square_metre,float> ArB = L1B * L2B;
fmt::print("{:%.30Q %q}\n * {:%.30Q %q}\n = {:%.30Q %q}\n\n",L1B,L2B,ArB);
area<square_metre, float> ArB = L1B * L2B;
fmt::print("{:%.30Q %q}\n * {:%.30Q %q}\n = {:%.30Q %q}\n\n", L1B, L2B, ArB);
}
} // namespace
+2 -2
View File
@@ -15,10 +15,10 @@
along with this program. If not, see http://www.gnu.org/licenses./
*/
#include <units/isq/si/length.h>
#include <units/format.h>
#include <units/quantity_io.h>
#include <units/isq/si/length.h>
#include <iostream>
#include <type_traits>
/*
get conversion factor from one dimensionally equivalent
+5 -1
View File
@@ -20,9 +20,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/quantity_io.h>
#include <units/base_dimension.h>
#include <units/isq/si/prefixes.h>
#include <units/quantity.h>
#include <units/quantity_io.h>
#include <units/unit.h>
#include <iostream>
#include <type_traits>
using namespace units;
+10 -9
View File
@@ -20,23 +20,24 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/format.h>
#include <units/generic/angle.h>
#include <units/isq/si/length.h>
#include <units/isq/si/energy.h>
#include <units/isq/si/torque.h>
#include <units/isq/si/force.h>
#include <units/isq/si/length.h>
#include <units/isq/si/torque.h> // IWYU pragma: keep
#include <units/quantity_io.h>
#include <iostream>
using namespace units;
using namespace units::isq::si::literals;
int main()
{
auto torque = 20.0_q_Nm_per_rad;
auto energy = 20.0_q_J;
using namespace units::references;
using namespace units::isq;
using namespace units::isq::si::references;
Angle auto angle = energy / torque;
Torque auto torque = 20.0 * (N * m / rad);
Energy auto energy = 20.0 * J;
units::Angle auto angle = energy / torque;
std::cout << angle << '\n';
}
+1 -3
View File
@@ -20,21 +20,19 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/concepts.h>
#include <units/format.h>
#include <units/isq/si/fps/density.h>
#include <units/isq/si/fps/length.h>
#include <units/isq/si/fps/mass.h>
#include <units/isq/si/fps/power.h>
#include <units/isq/si/fps/speed.h>
#include <units/isq/si/fps/volume.h>
#include <units/isq/si/length.h>
#include <units/isq/si/mass.h>
#include <units/isq/si/power.h>
#include <units/isq/si/speed.h>
#include <units/isq/si/volume.h>
#include <units/quantity.h>
#include <iostream>
#include <string_view>
using namespace units::isq;
+1
View File
@@ -23,6 +23,7 @@
#include "geographic.h"
#include <cmath>
#include <numbers>
#include <type_traits>
namespace {
+6 -1
View File
@@ -22,10 +22,15 @@
#pragma once
#include <units/format.h>
#include <units/isq/si/length.h>
#include <units/quantity_kind.h>
#include <fmt/format.h>
#include <limits>
#include <ostream>
// IWYU pragma: begin_exports
#include <compare>
// IWYU pragma: end_exports
namespace geographic {
+4
View File
@@ -21,9 +21,13 @@
// SOFTWARE.
#include "glide_computer.h"
#include <numeric>
#include <string_view>
namespace glide_computer {
using namespace units::isq;
task::legs task::make_legs(const waypoints& wpts)
{
task::legs res;
+34 -25
View File
@@ -22,12 +22,24 @@
#pragma once
// IWYU pragma: begin_exports
#include "geographic.h"
#include <units/format.h>
#include <units/math.h>
#include <units/isq/si/length.h>
#include <units/isq/si/speed.h>
#include <units/isq/si/international/length.h>
#include <units/isq/si/time.h>
#include <units/quantity_point_kind.h>
// IWYU pragma: end_exports
#include <units/format.h>
#include <units/math.h> // IWYU pragma: keep
#include <algorithm>
#include <array>
#include <initializer_list>
#include <iterator>
#include <ostream>
#include <ranges>
#include <string> // IWYU pragma: keep
#include <vector>
// An example of a really simplified tactical glide computer
// Simplifications:
@@ -43,9 +55,6 @@
// - no ground obstacles (i.e. mountains) to pass
// - flight path exactly on a shortest possible line to destination
using namespace units;
using namespace units::isq;
template<units::QuantityKind QK>
struct fmt::formatter<QK> : formatter<typename QK::quantity_type> {
template<typename FormatContext>
@@ -57,8 +66,8 @@ struct fmt::formatter<QK> : formatter<typename QK::quantity_type> {
namespace glide_computer {
template<QuantityKind QK1, QuantityKind QK2>
constexpr Dimensionless auto operator/(const QK1& lhs, const QK2& rhs)
template<units::QuantityKind QK1, units::QuantityKind QK2>
constexpr units::Dimensionless auto operator/(const QK1& lhs, const QK2& rhs)
requires(!units::QuantityKindRelatedTo<QK1, QK2>) && requires { lhs.common() / rhs.common();}
{
return lhs.common() / rhs.common();
@@ -66,24 +75,24 @@ constexpr Dimensionless auto operator/(const QK1& lhs, const QK2& rhs)
// kinds
using horizontal_kind = geographic::horizontal_kind;
struct vertical_kind : kind<vertical_kind, si::dim_length> {};
struct vertical_point_kind : point_kind<vertical_point_kind, vertical_kind> {};
struct velocity_kind : derived_kind<velocity_kind, horizontal_kind, si::dim_speed> {};
struct rate_of_climb_kind : derived_kind<rate_of_climb_kind, vertical_kind, si::dim_speed> {};
struct vertical_kind : units::kind<vertical_kind, units::isq::si::dim_length> {};
struct vertical_point_kind : units::point_kind<vertical_point_kind, vertical_kind> {};
struct velocity_kind : units::derived_kind<velocity_kind, horizontal_kind, units::isq::si::dim_speed> {};
struct rate_of_climb_kind : units::derived_kind<rate_of_climb_kind, vertical_kind, units::isq::si::dim_speed> {};
// https://en.wikipedia.org/wiki/Flight_planning#Units_of_measurement
// length
using distance = quantity_kind<horizontal_kind, si::kilometre>;
using height = quantity_kind<vertical_kind, si::metre>;
using altitude = quantity_point_kind<vertical_point_kind, si::metre>;
using distance = units::quantity_kind<horizontal_kind, units::isq::si::kilometre>;
using height = units::quantity_kind<vertical_kind, units::isq::si::metre>;
using altitude = units::quantity_point_kind<vertical_point_kind, units::isq::si::metre>;
// time
using duration = si::time<si::second>;
using timestamp = quantity_point<si::dim_time, si::second>;
using duration = units::isq::si::time<units::isq::si::second>;
using timestamp = units::quantity_point<units::isq::si::dim_time, units::isq::si::second>;
// speed
using velocity = quantity_kind<velocity_kind, si::kilometre_per_hour>;
using rate_of_climb = quantity_kind<rate_of_climb_kind, si::metre_per_second>;
using velocity = units::quantity_kind<velocity_kind, units::isq::si::kilometre_per_hour>;
using rate_of_climb = units::quantity_kind<rate_of_climb_kind, units::isq::si::metre_per_second>;
// text output
template<class CharT, class Traits>
@@ -117,7 +126,7 @@ struct glider {
std::array<polar_point, 1> polar;
};
constexpr Dimensionless auto glide_ratio(const glider::polar_point& polar) { return polar.v / -polar.climb; }
constexpr units::Dimensionless auto glide_ratio(const glider::polar_point& polar) { return polar.v / -polar.climb; }
struct weather {
height cloud_base;
@@ -160,10 +169,10 @@ public:
distance get_length() const { return length_; }
distance get_leg_dist_offset(size_t leg_index) const { return leg_index == 0 ? distance{} : leg_total_distances_[leg_index - 1]; }
size_t get_leg_index(distance dist) const
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
{
return static_cast<size_t>(std::ranges::distance(leg_total_distances_.cbegin(), std::ranges::lower_bound(leg_total_distances_, dist)));
return static_cast<std::size_t>(std::ranges::distance(leg_total_distances_.cbegin(), std::ranges::lower_bound(leg_total_distances_, dist)));
}
private:
@@ -188,7 +197,7 @@ struct aircraft_tow {
struct flight_point {
timestamp ts;
altitude alt;
size_t leg_idx = 0;
std::size_t leg_idx = 0;
distance dist{};
};
@@ -196,7 +205,7 @@ altitude terrain_level_alt(const task& t, const flight_point& pos);
constexpr height agl(altitude glider_alt, altitude terrain_level) { return glider_alt - terrain_level; }
inline si::length<si::kilometre> length_3d(distance dist, height h)
inline units::isq::si::length<units::isq::si::kilometre> length_3d(distance dist, height h)
{
// TODO support for hypot(q, q)
return sqrt(pow<2>(dist.common()) + pow<2>(h.common()));
+12 -1
View File
@@ -21,14 +21,25 @@
// SOFTWARE.
#include "glide_computer.h"
#include <units/bits/external/hacks.h>
#include <units/chrono.h>
#include <units/generic/dimensionless.h>
#include <units/isq/si/international/length.h>
#include <fmt/format.h>
#include <array>
#include <exception>
#include <iostream>
#include <iterator>
#include <string>
#include <utility>
#include <vector>
namespace {
using namespace glide_computer;
using namespace units::isq;
auto get_gliders()
{
using namespace si::references;
@@ -74,7 +85,7 @@ void print(const R& gliders)
std::cout << "- Name: " << g.name << "\n";
std::cout << "- Polar:\n";
for (const auto& p : g.polar)
fmt::print(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q}\n", p.climb, p.v, quantity_cast<one>(glide_ratio(g.polar[0])));
fmt::print(" * {:%.4Q %q} @ {:%.1Q %q} -> {:%.1Q %q}\n", p.climb, p.v, quantity_cast<units::one>(glide_ratio(g.polar[0])));
std::cout << "\n";
}
}
+5 -2
View File
@@ -21,8 +21,11 @@
// SOFTWARE.
#include <units/format.h>
#include <units/isq/si/international/speed.h>
#include <units/isq/si/speed.h>
#include <units/isq/si/international/length.h>
#include <units/isq/si/international/speed.h> // IWYU pragma: keep
#include <units/isq/si/length.h>
#include <units/isq/si/speed.h> // IWYU pragma: keep
#include <units/isq/si/time.h>
#include <units/quantity_io.h>
#include <iostream>
@@ -1,5 +1,29 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/format.h>
#include <units/isq/si/length.h>
#include <units/isq/si/speed.h>
#include <units/isq/si/time.h>
#include <iostream>
#include <array>
@@ -56,7 +80,7 @@ int main()
constexpr auto num_measurements = measurements.size();
std::array<state,num_measurements> track;
std::array<state, num_measurements> track;
// We need an initial estimate of track[0] as there is no previous state to get a prediction from
track[0].range.estimated_current_state = 30'000_q_m;
track[0].speed.estimated_current_state = 40.0_q_m_per_s;
+3 -2
View File
@@ -20,9 +20,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/isq/si/speed.h>
#include <units/isq/si/energy.h> // IWYU pragma: keep
#include <units/isq/si/force.h>
#include <units/isq/si/energy.h>
#include <units/isq/si/length.h>
#include <units/isq/si/speed.h> // IWYU pragma: keep
#include <units/format.h>
#include <units/quantity_io.h>
#include <linear_algebra.hpp>
+4 -1
View File
@@ -21,9 +21,12 @@
// SOFTWARE.
#include <units/isq/si/acceleration.h>
#include <units/isq/si/length.h>
#include <units/isq/si/speed.h>
#include <units/isq/si/time.h>
#include <units/quantity_io.h>
#include <cmath>
#include <compare>
#include <exception>
#include <iostream>
namespace {
+4 -2
View File
@@ -20,13 +20,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/isq/natural/constants.h>
#include <units/isq/natural/natural.h>
#include <units/isq/si/energy.h>
#include <units/isq/si/mass.h>
#include <units/isq/si/momentum.h>
#include <units/isq/si/speed.h>
#include <units/isq/si/speed.h> // IWYU pragma: keep
#include <units/isq/si/constants.h>
#include <units/math.h>
#include <units/quantity_io.h>
#include <exception>
#include <iostream>
namespace {
+4 -1
View File
@@ -20,8 +20,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include <units/isq/si/speed.h>
#include <units/isq/si/length.h>
#include <units/isq/si/speed.h> // IWYU pragma: keep
#include <units/isq/si/time.h>
#include <units/quantity_io.h>
#include <exception>
#include <iostream>
namespace {