diff --git a/include/st/traits.hpp b/include/st/traits.hpp index b86d7b1..9ec2cb9 100644 --- a/include/st/traits.hpp +++ b/include/st/traits.hpp @@ -30,9 +30,9 @@ namespace st template 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(this)->value() - unwrap(other)); + return ReturnT(lhs.value() - unwrap(rhs)); } }; @@ -55,35 +55,35 @@ namespace st template 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(this)->value() / unwrap(other)); + return ReturnT(lhs.value() / unwrap(rhs)); } }; template 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(this)->value() % unwrap(other)); + return ReturnT(lhs.value() % unwrap(rhs)); } }; template struct incrementable { - constexpr T &operator++() noexcept + friend constexpr T &operator++(T &t) noexcept { - ++static_cast(this)->value(); - return *static_cast(this); + ++t.value(); + return t; } - constexpr const T operator++(int) noexcept + friend constexpr const T operator++(T &t, int) noexcept { - T ret(static_cast(this)->value()); + T ret(t); - ++(static_cast(this)->value()); + ++t.value(); return ret; } }; @@ -91,17 +91,17 @@ namespace st template struct decrementable { - constexpr T &operator--() noexcept + friend constexpr T &operator--(T &t) noexcept { - --static_cast(this)->value(); - return *static_cast(this); + --t.value(); + return t; } - constexpr const T operator--(int) noexcept + friend constexpr const T operator--(T &t, int) noexcept { - T ret(static_cast(this)->value()); + T ret(t); - --(static_cast(this)->value()); + --t.value(); return ret; } };