mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-16 22:19:51 +07:00
postfix and infix increment operators
This commit is contained in:
40
README.md
40
README.md
@@ -508,6 +508,26 @@ auto operator~(const vec<T, Size>& xs);
|
|||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
auto operator!(const vec<T, Size>& xs);
|
auto operator!(const vec<T, Size>& xs);
|
||||||
|
|
||||||
|
// ++operator
|
||||||
|
|
||||||
|
template < typename T, size_t Size >
|
||||||
|
vec<T, Size>& operator++(vec<T, Size>& xs);
|
||||||
|
|
||||||
|
// --operator
|
||||||
|
|
||||||
|
template < typename T, size_t Size >
|
||||||
|
vec<T, Size>& operator--(vec<T, Size>& xs);
|
||||||
|
|
||||||
|
// operator++
|
||||||
|
|
||||||
|
template < typename T, size_t Size >
|
||||||
|
vec<T, Size> operator++(vec<T, Size>& xs, int);
|
||||||
|
|
||||||
|
// operator--
|
||||||
|
|
||||||
|
template < typename T, size_t Size >
|
||||||
|
vec<T, Size> operator--(vec<T, Size>& xs, int);
|
||||||
|
|
||||||
// operator+
|
// operator+
|
||||||
|
|
||||||
template < typename T, typename U, size_t Size >
|
template < typename T, typename U, size_t Size >
|
||||||
@@ -702,6 +722,26 @@ auto operator~(const mat<T, Size>& xs);
|
|||||||
template < typename T, size_t Size >
|
template < typename T, size_t Size >
|
||||||
auto operator!(const mat<T, Size>& xs);
|
auto operator!(const mat<T, Size>& xs);
|
||||||
|
|
||||||
|
// ++operator
|
||||||
|
|
||||||
|
template < typename T, size_t Size >
|
||||||
|
mat<T, Size>& operator++(mat<T, Size>& xs);
|
||||||
|
|
||||||
|
// --operator
|
||||||
|
|
||||||
|
template < typename T, size_t Size >
|
||||||
|
mat<T, Size>& operator--(mat<T, Size>& xs);
|
||||||
|
|
||||||
|
// operator++
|
||||||
|
|
||||||
|
template < typename T, size_t Size >
|
||||||
|
mat<T, Size> operator++(mat<T, Size>& xs, int);
|
||||||
|
|
||||||
|
// operator--
|
||||||
|
|
||||||
|
template < typename T, size_t Size >
|
||||||
|
mat<T, Size> operator--(mat<T, Size>& xs, int);
|
||||||
|
|
||||||
// operator+
|
// operator+
|
||||||
|
|
||||||
template < typename T, typename U, size_t Size >
|
template < typename T, typename U, size_t Size >
|
||||||
|
|||||||
@@ -187,6 +187,38 @@ namespace vmath_hpp
|
|||||||
return map_join([](const vec<T, Size>& x){ return !x; }, xs);
|
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+
|
// operator+
|
||||||
|
|
||||||
template < typename T, typename U, std::size_t Size >
|
template < typename T, typename U, std::size_t Size >
|
||||||
|
|||||||
@@ -238,6 +238,38 @@ namespace vmath_hpp
|
|||||||
return map_join([](T x){ return !x; }, xs);
|
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+
|
// operator+
|
||||||
|
|
||||||
template < typename T, typename U, std::size_t Size >
|
template < typename T, typename U, std::size_t Size >
|
||||||
|
|||||||
@@ -72,6 +72,20 @@ TEST_CASE("vmath/mat_fun") {
|
|||||||
STATIC_CHECK((int2x2(0,1,0,1) && int2x2(1,0,1,0)) == bool2x2(0,0,0,0));
|
STATIC_CHECK((int2x2(0,1,0,1) && int2x2(1,0,1,0)) == bool2x2(0,0,0,0));
|
||||||
STATIC_CHECK((int2x2(0,1,0,1) || int2x2(1,0,1,0)) == bool2x2(1,1,1,1));
|
STATIC_CHECK((int2x2(0,1,0,1) || int2x2(1,0,1,0)) == bool2x2(1,1,1,1));
|
||||||
|
|
||||||
|
{
|
||||||
|
int2x2 v{1,2,3,4};
|
||||||
|
CHECK(&v == &(++v));
|
||||||
|
CHECK(v == int2x2{2,3,4,5});
|
||||||
|
CHECK(&v == &(--v));
|
||||||
|
CHECK(v == int2x2{1,2,3,4});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int2x2 v{1,2,3,4};
|
||||||
|
CHECK(v++ == int2x2{1,2,3,4});
|
||||||
|
CHECK(v == int2x2{2,3,4,5});
|
||||||
|
CHECK(v-- == int2x2{2,3,4,5});
|
||||||
|
CHECK(v == int2x2{1,2,3,4});
|
||||||
|
}
|
||||||
{
|
{
|
||||||
int2x2 v{1,2,3,4};
|
int2x2 v{1,2,3,4};
|
||||||
CHECK(&v == &(v += 3));
|
CHECK(&v == &(v += 3));
|
||||||
|
|||||||
@@ -49,6 +49,20 @@ TEST_CASE("vmath/vec_fun") {
|
|||||||
STATIC_CHECK((int2(0,1) && int2(1,0)) == bool2(0,0));
|
STATIC_CHECK((int2(0,1) && int2(1,0)) == bool2(0,0));
|
||||||
STATIC_CHECK((int2(0,1) || int2(1,0)) == bool2(1,1));
|
STATIC_CHECK((int2(0,1) || int2(1,0)) == bool2(1,1));
|
||||||
|
|
||||||
|
{
|
||||||
|
int2 v{1,2};
|
||||||
|
CHECK(&v == &(++v));
|
||||||
|
CHECK(v == int2{2,3});
|
||||||
|
CHECK(&v == &(--v));
|
||||||
|
CHECK(v == int2{1,2});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int2 v{1,2};
|
||||||
|
CHECK(v++ == int2{1,2});
|
||||||
|
CHECK(v == int2{2,3});
|
||||||
|
CHECK(v-- == int2{2,3});
|
||||||
|
CHECK(v == int2{1,2});
|
||||||
|
}
|
||||||
{
|
{
|
||||||
int2 v{1,2};
|
int2 v{1,2};
|
||||||
CHECK(&v == &(v += 3));
|
CHECK(&v == &(v += 3));
|
||||||
|
|||||||
Reference in New Issue
Block a user