Skip to content

Commit 4d117b8

Browse files
committed
overload + and - operations for valarray_base
1 parent 65e1680 commit 4d117b8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cp-algo/linalg/vector.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ namespace cp_algo::linalg {
3232
}
3333
};
3434

35+
template<class vec, typename base>
36+
vec operator+(valarray_base<vec, base> const& a, valarray_base<vec, base> const& b) {
37+
return *static_cast<std::valarray<base> const*>(&a)
38+
+ *static_cast<std::valarray<base> const*>(&b);
39+
}
40+
template<class vec, typename base>
41+
vec operator-(valarray_base<vec, base> const& a, valarray_base<vec, base> const& b) {
42+
return *static_cast<std::valarray<base> const*>(&a)
43+
- *static_cast<std::valarray<base> const*>(&b);
44+
}
45+
3546
template<class vec, typename base>
3647
struct vec_base: valarray_base<vec, base> {
3748
using Base = valarray_base<vec, base>;

0 commit comments

Comments
 (0)