Skip to content

Commit ef62d3f

Browse files
<complex>: avoid unnecessary conversion of real arguments to complex (#2855)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent 5d00065 commit ef62d3f

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

stl/inc/complex

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,14 +1402,14 @@ _NODISCARD _CONSTEXPR20 complex<_Ty> operator+(const complex<_Ty>& _Left, const
14021402
template <class _Ty>
14031403
_NODISCARD _CONSTEXPR20 complex<_Ty> operator+(const complex<_Ty>& _Left, const _Ty& _Right) {
14041404
complex<_Ty> _Tmp(_Left);
1405-
_Tmp.real(_Tmp.real() + _Right);
1405+
_Tmp += _Right;
14061406
return _Tmp;
14071407
}
14081408

14091409
template <class _Ty>
14101410
_NODISCARD _CONSTEXPR20 complex<_Ty> operator+(const _Ty& _Left, const complex<_Ty>& _Right) {
1411-
complex<_Ty> _Tmp(_Left);
1412-
_Tmp += _Right;
1411+
complex<_Ty> _Tmp(_Right);
1412+
_Tmp += _Left;
14131413
return _Tmp;
14141414
}
14151415

@@ -1423,7 +1423,7 @@ _NODISCARD _CONSTEXPR20 complex<_Ty> operator-(const complex<_Ty>& _Left, const
14231423
template <class _Ty>
14241424
_NODISCARD _CONSTEXPR20 complex<_Ty> operator-(const complex<_Ty>& _Left, const _Ty& _Right) {
14251425
complex<_Ty> _Tmp(_Left);
1426-
_Tmp.real(_Tmp.real() - _Right);
1426+
_Tmp -= _Right;
14271427
return _Tmp;
14281428
}
14291429

@@ -1444,15 +1444,14 @@ _NODISCARD _CONSTEXPR20 complex<_Ty> operator*(const complex<_Ty>& _Left, const
14441444
template <class _Ty>
14451445
_NODISCARD _CONSTEXPR20 complex<_Ty> operator*(const complex<_Ty>& _Left, const _Ty& _Right) {
14461446
complex<_Ty> _Tmp(_Left);
1447-
_Tmp.real(_Tmp.real() * _Right);
1448-
_Tmp.imag(_Tmp.imag() * _Right);
1447+
_Tmp *= _Right;
14491448
return _Tmp;
14501449
}
14511450

14521451
template <class _Ty>
14531452
_NODISCARD _CONSTEXPR20 complex<_Ty> operator*(const _Ty& _Left, const complex<_Ty>& _Right) {
1454-
complex<_Ty> _Tmp(_Left);
1455-
_Tmp *= _Right;
1453+
complex<_Ty> _Tmp(_Right);
1454+
_Tmp *= _Left;
14561455
return _Tmp;
14571456
}
14581457

@@ -1466,8 +1465,7 @@ _NODISCARD _CONSTEXPR20 complex<_Ty> operator/(const complex<_Ty>& _Left, const
14661465
template <class _Ty>
14671466
_NODISCARD _CONSTEXPR20 complex<_Ty> operator/(const complex<_Ty>& _Left, const _Ty& _Right) {
14681467
complex<_Ty> _Tmp(_Left);
1469-
_Tmp.real(_Tmp.real() / _Right);
1470-
_Tmp.imag(_Tmp.imag() / _Right);
1468+
_Tmp /= _Right;
14711469
return _Tmp;
14721470
}
14731471

0 commit comments

Comments
 (0)