add <<, >> and <<=, >>= operators

This commit is contained in:
BlackMATov
2021-02-27 12:35:56 +07:00
parent 4f09d7859d
commit 017424641f
5 changed files with 230 additions and 0 deletions

View File

@@ -422,6 +422,64 @@ namespace vmath_hpp
return (xs = (xs ^ ys));
}
// operator<<
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator<<(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return x << y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator<<(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return x << y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator<<(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return x << y; }, xs, ys);
}
// operator<<=
template < typename T, std::size_t Size >
constexpr mat<T, Size>& operator<<=(mat<T, Size>& xs, T y) {
return (xs = (xs << y));
}
template < typename T, std::size_t Size >
constexpr mat<T, Size>& operator<<=(mat<T, Size>& xs, const mat<T, Size>& ys) {
return (xs = (xs << ys));
}
// operator>>
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator>>(const mat<T, Size>& xs, T y) {
return map_join([y](const vec<T, Size>& x){ return x >> y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator>>(T x, const mat<T, Size>& ys) {
return map_join([x](const vec<T, Size>& y){ return x >> y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator>>(const mat<T, Size>& xs, const mat<T, Size>& ys) {
return map_join([](const vec<T, Size>& x, const vec<T, Size>& y){ return x >> y; }, xs, ys);
}
// operator>>=
template < typename T, std::size_t Size >
constexpr mat<T, Size>& operator>>=(mat<T, Size>& xs, T y) {
return (xs = (xs >> y));
}
template < typename T, std::size_t Size >
constexpr mat<T, Size>& operator>>=(mat<T, Size>& xs, const mat<T, Size>& ys) {
return (xs = (xs >> ys));
}
// operator&&
template < typename T, std::size_t Size >

View File

@@ -473,6 +473,64 @@ namespace vmath_hpp
return (xs = (xs ^ ys));
}
// operator<<
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator<<(const vec<T, Size>& xs, T y) {
return map_join([y](T x){ return x << y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator<<(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return x << y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator<<(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return x << y; }, xs, ys);
}
// operator<<=
template < typename T, std::size_t Size >
constexpr vec<T, Size>& operator<<=(vec<T, Size>& xs, T y) {
return (xs = (xs << y));
}
template < typename T, std::size_t Size >
constexpr vec<T, Size>& operator<<=(vec<T, Size>& xs, const vec<T, Size>& ys) {
return (xs = (xs << ys));
}
// operator>>
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator>>(const vec<T, Size>& xs, T y) {
return map_join([y](T x){ return x >> y; }, xs);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator>>(T x, const vec<T, Size>& ys) {
return map_join([x](T y){ return x >> y; }, ys);
}
template < typename T, std::size_t Size >
[[nodiscard]] constexpr auto operator>>(const vec<T, Size>& xs, const vec<T, Size>& ys) {
return map_join([](T x, T y){ return x >> y; }, xs, ys);
}
// operator>>=
template < typename T, std::size_t Size >
constexpr vec<T, Size>& operator>>=(vec<T, Size>& xs, T y) {
return (xs = (xs >> y));
}
template < typename T, std::size_t Size >
constexpr vec<T, Size>& operator>>=(vec<T, Size>& xs, const vec<T, Size>& ys) {
return (xs = (xs >> ys));
}
// operator&&
template < typename T, std::size_t Size >