Skip to content

Commit

Permalink
<complex>: avoid unnecessary conversion of real arguments to complex (
Browse files Browse the repository at this point in the history
#2855)

Co-authored-by: Stephan T. Lavavej <[email protected]>
  • Loading branch information
MattStephanson and StephanTLavavej committed Jul 14, 2022
1 parent 5d00065 commit ef62d3f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions stl/inc/complex
Original file line number Diff line number Diff line change
Expand Up @@ -1402,14 +1402,14 @@ _NODISCARD _CONSTEXPR20 complex<_Ty> operator+(const complex<_Ty>& _Left, const
template <class _Ty>
_NODISCARD _CONSTEXPR20 complex<_Ty> operator+(const complex<_Ty>& _Left, const _Ty& _Right) {
complex<_Ty> _Tmp(_Left);
_Tmp.real(_Tmp.real() + _Right);
_Tmp += _Right;
return _Tmp;
}

template <class _Ty>
_NODISCARD _CONSTEXPR20 complex<_Ty> operator+(const _Ty& _Left, const complex<_Ty>& _Right) {
complex<_Ty> _Tmp(_Left);
_Tmp += _Right;
complex<_Ty> _Tmp(_Right);
_Tmp += _Left;
return _Tmp;
}

Expand All @@ -1423,7 +1423,7 @@ _NODISCARD _CONSTEXPR20 complex<_Ty> operator-(const complex<_Ty>& _Left, const
template <class _Ty>
_NODISCARD _CONSTEXPR20 complex<_Ty> operator-(const complex<_Ty>& _Left, const _Ty& _Right) {
complex<_Ty> _Tmp(_Left);
_Tmp.real(_Tmp.real() - _Right);
_Tmp -= _Right;
return _Tmp;
}

Expand All @@ -1444,15 +1444,14 @@ _NODISCARD _CONSTEXPR20 complex<_Ty> operator*(const complex<_Ty>& _Left, const
template <class _Ty>
_NODISCARD _CONSTEXPR20 complex<_Ty> operator*(const complex<_Ty>& _Left, const _Ty& _Right) {
complex<_Ty> _Tmp(_Left);
_Tmp.real(_Tmp.real() * _Right);
_Tmp.imag(_Tmp.imag() * _Right);
_Tmp *= _Right;
return _Tmp;
}

template <class _Ty>
_NODISCARD _CONSTEXPR20 complex<_Ty> operator*(const _Ty& _Left, const complex<_Ty>& _Right) {
complex<_Ty> _Tmp(_Left);
_Tmp *= _Right;
complex<_Ty> _Tmp(_Right);
_Tmp *= _Left;
return _Tmp;
}

Expand All @@ -1466,8 +1465,7 @@ _NODISCARD _CONSTEXPR20 complex<_Ty> operator/(const complex<_Ty>& _Left, const
template <class _Ty>
_NODISCARD _CONSTEXPR20 complex<_Ty> operator/(const complex<_Ty>& _Left, const _Ty& _Right) {
complex<_Ty> _Tmp(_Left);
_Tmp.real(_Tmp.real() / _Right);
_Tmp.imag(_Tmp.imag() / _Right);
_Tmp /= _Right;
return _Tmp;
}

Expand Down

0 comments on commit ef62d3f

Please sign in to comment.