Skip to content

Commit

Permalink
refactor: apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JohelEGP committed Sep 23, 2023
1 parent 3661010 commit 8e5d84d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
9 changes: 5 additions & 4 deletions example/include/ranged_representation.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,25 @@ class ranged_representation : public validated_type<T, is_in_range_t<T, Min, Max
return ranged_representation(-this->value());
}

friend constexpr ranged_representation operator-(const ranged_representation& lhs, const ranged_representation& rhs)
[[nodiscard]] friend constexpr ranged_representation operator-(const ranged_representation& lhs,
const ranged_representation& rhs)
{
return ranged_representation(lhs.value() - rhs.value());
}

constexpr ranged_representation& operator+=(ranged_representation that)
constexpr ranged_representation& operator+=(const ranged_representation& that)
{
this->value() += that.value();
gsl_Expects(validate(this->value()));
return *this;
}
constexpr ranged_representation& operator-=(ranged_representation that)
constexpr ranged_representation& operator-=(const ranged_representation& that)
{
this->value() -= that.value();
gsl_Expects(validate(this->value()));
return *this;
}
constexpr ranged_representation& operator*=(T rhs)
constexpr ranged_representation& operator*=(const T& rhs)
{
this->value() *= rhs;
gsl_Expects(validate(this->value()));
Expand Down
4 changes: 2 additions & 2 deletions example/measurement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ class measurement {
return measurement(lhs.value() - rhs.value(), hypot(lhs.uncertainty(), rhs.uncertainty()));
}

constexpr measurement& operator+=(measurement that)
constexpr measurement& operator+=(const measurement& that)
{
value_ = *this + that;
return *this;
}

constexpr measurement& operator-=(measurement that)
constexpr measurement& operator-=(const measurement& that)
{
value_ = *this - that;
return *this;
Expand Down
20 changes: 10 additions & 10 deletions src/core/include/mp-units/numbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ namespace mp_units {
template<typename T>
struct number_scalar;

namespace detail {

template<typename T>
struct inferred_number_zero {};
using number_difference_t = decltype(std::declval<const T>() - std::declval<const T>());
template<typename T>
struct inferred_number_one {};
using number_scalar_t = number_scalar<T>::type;

} // namespace detail
namespace detail {

template<typename T>
using number_difference_t = decltype(std::declval<const T>() - std::declval<const T>());
struct inferred_number_zero {};
template<typename T>
using number_scalar_t = number_scalar<T>::type;
struct inferred_number_one {};

template<typename T>
concept is_inferred_number = std::regular<number_scalar_t<T>>;

} // namespace detail

template<typename T>
struct is_number : std::bool_constant<is_inferred_number<T>> {};
struct is_number : std::bool_constant<detail::is_inferred_number<T>> {};
template<typename T>
struct is_complex_number : std::false_type {};
template<typename T>
Expand Down Expand Up @@ -266,11 +266,11 @@ concept inferable_identities = std::common_with<T, number_difference_t<T>> && st

template<detail::inferable_identities T>
struct inferred_number_zero<T> {
auto static constexpr value = T(0);
static constexpr auto value = T(0);
};
template<detail::inferable_identities T>
struct inferred_number_one<T> {
auto static constexpr value = T(1);
static constexpr auto value = T(1);
};

} // namespace detail
Expand Down
2 changes: 1 addition & 1 deletion test/unit_test/runtime/linear_algebra_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ template<typename Rep>
inline constexpr bool mp_units::is_vector<vector<Rep>> = true;

template<typename Rep>
constexpr bool mp_units::is_number_v<vector<Rep>> = mp_units::is_number_v<Rep>;
struct mp_units::number_scalar<vector<Rep>> : std::type_identity<Rep> {};

template<typename Rep>
std::ostream& operator<<(std::ostream& os, const vector<Rep>& v)
Expand Down

0 comments on commit 8e5d84d

Please sign in to comment.