Skip to content

Commit

Permalink
Switch remaining regular operator overloadings to friend
Browse files Browse the repository at this point in the history
  • Loading branch information
doom committed Aug 4, 2019
1 parent 394d8fa commit 74d4292
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions include/st/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ namespace st
template <typename T, typename OtherOperandT = T, typename ReturnT = T>
struct subtractable
{
constexpr ReturnT operator-(const OtherOperandT &other) const noexcept
friend constexpr ReturnT operator-(const T &lhs, const OtherOperandT &rhs) noexcept
{
return ReturnT(static_cast<const T *>(this)->value() - unwrap(other));
return ReturnT(lhs.value() - unwrap(rhs));
}
};

Expand All @@ -55,53 +55,53 @@ namespace st
template <typename T, typename OtherOperandT = T, typename ReturnT = T>
struct dividable
{
constexpr ReturnT operator/(const OtherOperandT &other) const noexcept
friend constexpr ReturnT operator/(const T &lhs, const OtherOperandT &rhs) noexcept
{
return ReturnT(static_cast<const T *>(this)->value() / unwrap(other));
return ReturnT(lhs.value() / unwrap(rhs));
}
};

template <typename T, typename OtherOperandT = T, typename ReturnT = T>
struct modulable
{
constexpr ReturnT operator%(const OtherOperandT &other) const noexcept
friend constexpr ReturnT operator%(const T &lhs, const OtherOperandT &rhs) noexcept
{
return ReturnT(static_cast<const T *>(this)->value() % unwrap(other));
return ReturnT(lhs.value() % unwrap(rhs));
}
};

template <typename T>
struct incrementable
{
constexpr T &operator++() noexcept
friend constexpr T &operator++(T &t) noexcept
{
++static_cast<T *>(this)->value();
return *static_cast<T *>(this);
++t.value();
return t;
}

constexpr const T operator++(int) noexcept
friend constexpr const T operator++(T &t, int) noexcept
{
T ret(static_cast<T *>(this)->value());
T ret(t);

++(static_cast<T *>(this)->value());
++t.value();
return ret;
}
};

template <typename T>
struct decrementable
{
constexpr T &operator--() noexcept
friend constexpr T &operator--(T &t) noexcept
{
--static_cast<T *>(this)->value();
return *static_cast<T *>(this);
--t.value();
return t;
}

constexpr const T operator--(int) noexcept
friend constexpr const T operator--(T &t, int) noexcept
{
T ret(static_cast<T *>(this)->value());
T ret(t);

--(static_cast<T *>(this)->value());
--t.value();
return ret;
}
};
Expand Down

0 comments on commit 74d4292

Please sign in to comment.