Skip to content

Commit 76152e2

Browse files
authored
Merge pull request #152 from FabienPean/feature/assignment_operator_signature
Make assignment operator signature like built-in types
2 parents e0fc271 + 085860f commit 76152e2

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

Fastor/tensor/TensorInplaceOperators.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,54 @@
44
// CRTP Overloads for nth rank Tensors
55
//---------------------------------------------------------------------------------------------//
66
template<typename Derived, size_t DIMS>
7-
FASTOR_INLINE void operator +=(const AbstractTensor<Derived,DIMS>& src_) {
7+
FASTOR_INLINE auto& operator +=(const AbstractTensor<Derived,DIMS>& src_) {
88
assign_add(*this, src_.self());
9+
return *this;
910
}
1011

1112
template<typename Derived, size_t DIMS>
12-
FASTOR_INLINE void operator -=(const AbstractTensor<Derived,DIMS>& src_) {
13+
FASTOR_INLINE auto& operator -=(const AbstractTensor<Derived,DIMS>& src_) {
1314
assign_sub(*this, src_.self());
15+
return *this;
1416
}
1517

1618
template<typename Derived, size_t DIMS>
17-
FASTOR_INLINE void operator *=(const AbstractTensor<Derived,DIMS>& src_) {
19+
FASTOR_INLINE auto& operator *=(const AbstractTensor<Derived,DIMS>& src_) {
1820
assign_mul(*this, src_.self());
21+
return *this;
1922
}
2023

2124
template<typename Derived, size_t DIMS>
22-
FASTOR_INLINE void operator /=(const AbstractTensor<Derived,DIMS>& src_) {
25+
FASTOR_INLINE auto& operator /=(const AbstractTensor<Derived,DIMS>& src_) {
2326
assign_div(*this, src_.self());
27+
return *this;
2428
}
2529
//---------------------------------------------------------------------------------------------//
2630

2731
// Scalar overloads for in-place operators
2832
//---------------------------------------------------------------------------------------------//
2933
template<typename U=T, enable_if_t_<is_arithmetic_v_<U>,bool> = 0 >
30-
FASTOR_INLINE void operator +=(U num) {
34+
FASTOR_INLINE auto& operator +=(U num) {
3135
trivial_assign_add(*this, num);
36+
return *this;
3237
}
3338

3439
template<typename U=T, enable_if_t_<is_arithmetic_v_<U>,bool> = 0 >
35-
FASTOR_INLINE void operator -=(U num) {
40+
FASTOR_INLINE auto& operator -=(U num) {
3641
trivial_assign_sub(*this, num);
42+
return *this;
3743
}
3844

3945
template<typename U=T, enable_if_t_<is_arithmetic_v_<U>,bool> = 0 >
40-
FASTOR_INLINE void operator *=(U num) {
46+
FASTOR_INLINE auto& operator *=(U num) {
4147
trivial_assign_mul(*this, num);
48+
return *this;
4249
}
4350

4451
template<typename U=T, enable_if_t_<is_arithmetic_v_<U>,bool> = 0 >
45-
FASTOR_INLINE void operator /=(U num) {
52+
FASTOR_INLINE auto& operator /=(U num) {
4653
trivial_assign_div(*this, num);
54+
return *this;
4755
}
4856
//---------------------------------------------------------------------------------------------//
4957

0 commit comments

Comments
 (0)