Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/complex/operator="

From cppreference.com
< cpp‎ | numeric‎ | complex
m (+trivial link.)
(Added LWG issue #3935 DR.)
 
Line 1: Line 1:
 
{{cpp/numeric/complex/title|operator{{=}}}}
 
{{cpp/numeric/complex/title|operator{{=}}}}
 
{{cpp/numeric/complex/navbar}}
 
{{cpp/numeric/complex/navbar}}
{{dcl begin}}
 
  
 +
 
{{dcl h|All specializations}}
 
{{dcl h|All specializations}}
 
{{dcl rev multi|num=1|until1=c++20|dcl1=
 
{{dcl rev multi|num=1|until1=c++20|dcl1=
Line 26: Line 26:
 
{{dcl rev multi|num=3|until1=c++20|dcl1=
 
{{dcl rev multi|num=3|until1=c++20|dcl1=
 
complex& operator=( F x );
 
complex& operator=( F x );
|since2=c++20|until2=c++23<!-- may be an LWG issue -->|dcl2=
+
|since2=c++20|until2=c++23|dcl2=
 
constexpr complex& operator=( F x );
 
constexpr complex& operator=( F x );
 
}}
 
}}
Line 48: Line 48:
 
===Notes===
 
===Notes===
 
The copy assignment operator is required to be [[cpp/language/copy assignment#Trivial copy assignment operator|trivial]] since C++23, but implementations generally make it trivial in all modes.
 
The copy assignment operator is required to be [[cpp/language/copy assignment#Trivial copy assignment operator|trivial]] since C++23, but implementations generally make it trivial in all modes.
 +
 +
 +
 +
 +
  
 
===See also===
 
===See also===

Latest revision as of 20:38, 7 November 2023

 
 
 
 
All specializations
(1)
complex& operator=( const complex& cx );
(until C++20)
constexpr complex& operator=( const complex& cx );
(since C++20)
(2)
template< class X >
complex& operator=( const std::complex<X>& cx );
(until C++20)
template< class X >
constexpr complex& operator=( const std::complex<X>& cx );
(since C++20)
Primary template complex<T>
(3)
complex& operator=( const T& x );
(until C++20)
constexpr complex& operator=( const T& x );
(since C++20)
Specializations for standard floating-point types complex<F> (until C++23)
(3)
complex& operator=( F x );
(until C++20)
constexpr complex& operator=( F x );
(since C++20)
(until C++23)

Assigns new values to the contents.

1,2) Assigns cx.real() and cx.imag() to the real and the imaginary parts of the complex number respectively. The copy assignment operator (1) is trivial when T is a floating-point type.(since C++23)
3) Assigns x to the real part of the complex number. Imaginary part is set to zero.

Contents

[edit] Parameters

x - value to assign
cx - complex value to assign

[edit] Return value

*this

[edit] Notes

The copy assignment operator is required to be trivial since C++23, but implementations generally make it trivial in all modes.

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 3935 C++98 the description of overload (2) was missing added

[edit] See also

constructs a complex number
(public member function) [edit]
a std::complex literal representing purely imaginary number
(function) [edit]