postfix and infix increment operators

This commit is contained in:
BlackMATov
2021-02-26 12:32:13 +07:00
parent 325e0e7e9f
commit dd16c24249
5 changed files with 132 additions and 0 deletions

View File

@@ -187,6 +187,38 @@ namespace vmath_hpp
return map_join([](const vec<T, Size>& x){ return !x; }, xs);
}
// ++operator
template < typename T, std::size_t Size >
constexpr mat<T, Size>& operator++(mat<T, Size>& xs) {
return (xs = xs + T{1});
}
// --operator
template < typename T, std::size_t Size >
constexpr mat<T, Size>& operator--(mat<T, Size>& xs) {
return (xs = xs - T{1});
}
// operator++
template < typename T, std::size_t Size >
constexpr mat<T, Size> operator++(mat<T, Size>& xs, int) {
mat<T, Size> ys = xs;
++xs;
return ys;
}
// operator--
template < typename T, std::size_t Size >
constexpr mat<T, Size> operator--(mat<T, Size>& xs, int) {
mat<T, Size> ys = xs;
--xs;
return ys;
}
// operator+
template < typename T, typename U, std::size_t Size >

View File

@@ -238,6 +238,38 @@ namespace vmath_hpp
return map_join([](T x){ return !x; }, xs);
}
// ++operator
template < typename T, std::size_t Size >
constexpr vec<T, Size>& operator++(vec<T, Size>& xs) {
return (xs = xs + T{1});
}
// --operator
template < typename T, std::size_t Size >
constexpr vec<T, Size>& operator--(vec<T, Size>& xs) {
return (xs = xs - T{1});
}
// operator++
template < typename T, std::size_t Size >
constexpr vec<T, Size> operator++(vec<T, Size>& xs, int) {
vec<T, Size> ys = xs;
++xs;
return ys;
}
// operator--
template < typename T, std::size_t Size >
constexpr vec<T, Size> operator--(vec<T, Size>& xs, int) {
vec<T, Size> ys = xs;
--xs;
return ys;
}
// operator+
template < typename T, typename U, std::size_t Size >