Skip to content

Commit

Permalink
fix(example): make ranged_representation model vector_space
Browse files Browse the repository at this point in the history
  • Loading branch information
JohelEGP committed Sep 23, 2023
1 parent 3ce672d commit 48b931f
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions example/include/ranged_representation.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,19 @@ class ranged_representation : public validated_type<T, is_in_range_t<T, Min, Max
using validated_type<T, is_in_range_t<T, Min, Max>>::validated_type;
constexpr ranged_representation() : validated_type<T, is_in_range_t<T, Min, Max>>(T{}) {}

[[nodiscard]] constexpr ranged_representation operator-() const
requires requires(T t) { -t; }
{
return ranged_representation(-this->value());
}

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

constexpr ranged_representation& operator+=(const ranged_representation& that)
constexpr ranged_representation& operator+=(const T& that)
{
this->value() += that.value();
gsl_Expects(validate(this->value()));
return *this;
return *this = ranged_representation(this->value() + that);
}
constexpr ranged_representation& operator-=(const ranged_representation& that)
constexpr ranged_representation& operator-=(const T& that)
{
this->value() -= that.value();
gsl_Expects(validate(this->value()));
return *this;
return *this = ranged_representation(this->value() - that);
}
constexpr ranged_representation& operator*=(const T& rhs)
{
this->value() *= rhs;
gsl_Expects(validate(this->value()));
return *this;
return *this = ranged_representation(this->value() * rhs);
}
};

Expand Down

0 comments on commit 48b931f

Please sign in to comment.