Skip to content

Commit

Permalink
fix includes (and use curly braces for constructor calls in measurmen…
Browse files Browse the repository at this point in the history
…t.cpp as per c++ core guidelines)
  • Loading branch information
burnpanck committed Nov 12, 2024
1 parent 0c1971e commit 4ef0210
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
22 changes: 8 additions & 14 deletions example/measurement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,51 +70,51 @@ class measurement {
[[nodiscard]] friend constexpr measurement operator+(const measurement& lhs, const measurement& rhs)
{
using namespace std;
return measurement{std::in_place, lhs.value() + rhs.value(), hypot(lhs.uncertainty(), rhs.uncertainty())};
return measurement{lhs.value() + rhs.value(), hypot(lhs.uncertainty(), rhs.uncertainty())};
}

[[nodiscard]] friend constexpr measurement operator-(const measurement& lhs, const measurement& rhs)
{
using namespace std;
return measurement{std::in_place, lhs.value() - rhs.value(), hypot(lhs.uncertainty(), rhs.uncertainty())};
return measurement{lhs.value() - rhs.value(), hypot(lhs.uncertainty(), rhs.uncertainty())};
}

[[nodiscard]] friend constexpr measurement operator*(const measurement& lhs, const measurement& rhs)
{
const auto val = lhs.value() * rhs.value();
using namespace std;
return measurement(val, val * hypot(lhs.relative_uncertainty(), rhs.relative_uncertainty()));
return measurement{val, val * hypot(lhs.relative_uncertainty(), rhs.relative_uncertainty())};
}

[[nodiscard]] friend constexpr measurement operator*(const measurement& lhs, const value_type& value)
{
const auto val = lhs.value() * value;
return measurement(val, val * lhs.relative_uncertainty());
return measurement{val, val * lhs.relative_uncertainty()};
}

[[nodiscard]] friend constexpr measurement operator*(const value_type& value, const measurement& rhs)
{
const auto val = rhs.value() * value;
return measurement(val, val * rhs.relative_uncertainty());
return measurement{val, val * rhs.relative_uncertainty()};
}

[[nodiscard]] friend constexpr measurement operator/(const measurement& lhs, const measurement& rhs)
{
const auto val = lhs.value() / rhs.value();
using namespace std;
return measurement(val, val * hypot(lhs.relative_uncertainty(), rhs.relative_uncertainty()));
return measurement{val, val * hypot(lhs.relative_uncertainty(), rhs.relative_uncertainty())};
}

[[nodiscard]] friend constexpr measurement operator/(const measurement& lhs, const value_type& value)
{
const auto val = lhs.value() / value;
return measurement(val, val * lhs.relative_uncertainty());
return measurement{val, val * lhs.relative_uncertainty()};
}

[[nodiscard]] friend constexpr measurement operator/(const value_type& value, const measurement& rhs)
{
const auto val = value / rhs.value();
return measurement(val, val * rhs.relative_uncertainty());
return measurement{val, val * rhs.relative_uncertainty()};
}

[[nodiscard]] constexpr auto operator<=>(const measurement&) const = default;
Expand All @@ -127,12 +127,6 @@ class measurement {
private:
value_type value_{};
value_type uncertainty_{};

// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
constexpr measurement(std::in_place_t, value_type val, value_type err) :
value_(std::move(val)), uncertainty_(std::move(err))
{
}
};

} // namespace
Expand Down
1 change: 1 addition & 0 deletions src/core/include/mp-units/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <mp-units/framework/quantity_spec_concepts.h>
#include <mp-units/framework/reference.h>
#include <mp-units/framework/representation_concepts.h>
#include <mp-units/framework/scaling.h>
#include <mp-units/framework/symbol_text.h>
#include <mp-units/framework/system_reference.h>
#include <mp-units/framework/unit.h>
Expand Down

0 comments on commit 4ef0210

Please sign in to comment.