Skip to content

Commit

Permalink
Cleanup compound operators
Browse files Browse the repository at this point in the history
  • Loading branch information
wichtounet committed Oct 31, 2023
1 parent a99a915 commit 21c1747
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions include/etl/builder/binary_expression_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ auto operator%(LE lhs, RE&& rhs) requires std::convertible_to<LE, value_t<RE>> {

// Compound operators

// TODO: Generalize the change to std::forward and decltype(auto)

/*!
* \brief Compound addition of the right hand side to the left hand side
* \param lhs The left hand side, will be changed
Expand All @@ -254,7 +252,7 @@ decltype(auto) operator+=(LE&& lhs, RE rhs) {
* \return the left hand side
*/
template <simple_lhs LE, etl_expr RE>
decltype(auto) operator+=(LE&& lhs, RE&& rhs) {
decltype(auto) operator+=(LE&& lhs, const RE & rhs) {
validate_expression(lhs, rhs);
rhs.assign_add_to(lhs);
return std::forward<LE>(lhs);
Expand All @@ -267,9 +265,9 @@ decltype(auto) operator+=(LE&& lhs, RE&& rhs) {
* \return the left hand side
*/
template <simple_lhs LE, arithmetic RE>
LE& operator-=(LE&& lhs, RE rhs) {
decltype(auto) operator-=(LE&& lhs, RE rhs) {
etl::scalar<RE>(rhs).assign_sub_to(lhs);
return lhs;
return std::forward<LE>(lhs);
}

/*!
Expand All @@ -279,10 +277,10 @@ LE& operator-=(LE&& lhs, RE rhs) {
* \return the left hand side
*/
template <simple_lhs LE, etl_expr RE>
LE& operator-=(LE&& lhs, RE&& rhs) {
decltype(auto) operator-=(LE&& lhs, const RE & rhs) {
validate_expression(lhs, rhs);
rhs.assign_sub_to(lhs);
return lhs;
return std::forward<LE>(lhs);
}

/*!
Expand All @@ -292,9 +290,9 @@ LE& operator-=(LE&& lhs, RE&& rhs) {
* \return the left hand side
*/
template <simple_lhs LE, arithmetic RE>
LE& operator*=(LE&& lhs, RE rhs) {
decltype(auto) operator*=(LE&& lhs, RE rhs) {
etl::scalar<RE>(rhs).assign_mul_to(lhs);
return lhs;
return std::forward<LE>(lhs);
}

/*!
Expand All @@ -304,10 +302,10 @@ LE& operator*=(LE&& lhs, RE rhs) {
* \return the left hand side
*/
template <simple_lhs LE, etl_expr RE>
LE& operator*=(LE&& lhs, RE&& rhs) {
decltype(auto) operator*=(LE&& lhs, const RE & rhs) {
validate_expression(lhs, rhs);
rhs.assign_mul_to(lhs);
return lhs;
return std::forward<LE>(lhs);
}

/*!
Expand All @@ -317,9 +315,9 @@ LE& operator*=(LE&& lhs, RE&& rhs) {
* \return the left hand side
*/
template <simple_lhs LE, arithmetic RE>
LE& operator>>=(LE&& lhs, RE rhs) {
decltype(auto) operator>>=(LE&& lhs, RE rhs) {
etl::scalar<RE>(rhs).assign_mul_to(lhs);
return lhs;
return std::forward<LE>(lhs);
}

/*!
Expand All @@ -329,10 +327,10 @@ LE& operator>>=(LE&& lhs, RE rhs) {
* \return the left hand side
*/
template <simple_lhs LE, etl_expr RE>
LE& operator>>=(LE&& lhs, RE&& rhs) {
decltype(auto) operator>>=(LE&& lhs, const RE & rhs) {
validate_expression(lhs, rhs);
rhs.assign_mul_to(lhs);
return lhs;
return std::forward<LE>(lhs);
}

/*!
Expand All @@ -342,9 +340,9 @@ LE& operator>>=(LE&& lhs, RE&& rhs) {
* \return the left hand side
*/
template <simple_lhs LE, arithmetic RE>
LE& operator/=(LE&& lhs, RE rhs) {
decltype(auto) operator/=(LE&& lhs, RE rhs) {
etl::scalar<RE>(rhs).assign_div_to(lhs);
return lhs;
return std::forward<LE>(lhs);
}

/*!
Expand All @@ -354,10 +352,10 @@ LE& operator/=(LE&& lhs, RE rhs) {
* \return the left hand side
*/
template <simple_lhs LE, etl_expr RE>
LE& operator/=(LE&& lhs, RE&& rhs) {
decltype(auto) operator/=(LE&& lhs, const RE & rhs) {
validate_expression(lhs, rhs);
rhs.assign_div_to(lhs);
return lhs;
return std::forward<LE>(lhs);
}

/*!
Expand All @@ -367,9 +365,9 @@ LE& operator/=(LE&& lhs, RE&& rhs) {
* \return the left hand side
*/
template <simple_lhs LE, arithmetic RE>
LE& operator%=(LE&& lhs, RE rhs) {
decltype(auto) operator%=(LE&& lhs, RE rhs) {
etl::scalar<RE>(rhs).assign_mod_to(lhs);
return lhs;
return std::forward<LE>(lhs);
}

/*!
Expand All @@ -379,10 +377,10 @@ LE& operator%=(LE&& lhs, RE rhs) {
* \return the left hand side
*/
template <simple_lhs LE, etl_expr RE>
LE& operator%=(LE&& lhs, RE&& rhs) {
decltype(auto) operator%=(LE&& lhs, const RE & rhs) {
validate_expression(lhs, rhs);
rhs.assign_mod_to(lhs);
return lhs;
return std::forward<LE>(lhs);
}

// Comparison
Expand Down

0 comments on commit 21c1747

Please sign in to comment.