std::complex<T>::complex - cppreference.com

From cppreference.com

Primary template (std::complex<T>)

complex(constT&re=T(),constT&im=T()); (1)(until C++14)constexprcomplex(constT&re=T(),constT&im=T());(since C++14)complex(constcomplex&other); (2)(until C++14)constexprcomplex(constcomplex&other);(since C++14)
(until C++23)constexprcomplex(constcomplex&other)=default;(since C++23)template<classX>complex(constcomplex<X>&other); (3)(until C++14)template<classX>constexprcomplex(constcomplex<X>&other);(since C++14)
(until C++23)template<classX>constexprexplicit(/* see below */)complex(constcomplex<X>&other);(since C++23)Standard explicit specializationstd::complex<float>(until C++23)

complex(floatre=0.0f,floatim=0.0f); (1)(until C++11)constexprcomplex(floatre=0.0f,floatim=0.0f);(since C++11)constexprcomplex(constcomplex<float>&other)=default; (2) (since C++20)explicitcomplex(constcomplex<double>&other);explicitcomplex(constcomplex<longdouble>&other); (3)(until C++11)constexprexplicitcomplex(constcomplex<double>&other);constexprexplicitcomplex(constcomplex<longdouble>&other);(since C++11)Standard explicit specializationstd::complex<double>(until C++23)

complex(doublere=0.0,doubleim=0.0); (1)(until C++11)constexprcomplex(doublere=0.0,doubleim=0.0);(since C++11)constexprcomplex(constcomplex<double>&other)=default; (2) (since C++20)complex(constcomplex<float>&other);explicitcomplex(constcomplex<longdouble>&other); (3)(until C++11)constexprcomplex(constcomplex<float>&other);constexprexplicitcomplex(constcomplex<longdouble>&other);(since C++11)Standard explicit specializationstd::complex<longdouble>(until C++23)

complex(longdoublere=0.0L,longdoubleim=0.0L); (1)(until C++11)constexprcomplex(longdoublere=0.0L,longdoubleim=0.0L);(since C++11)constexprcomplex(constcomplex<longdouble>&other)=default; (2) (since C++20)complex(constcomplex<float>&other);complex(constcomplex<double>&other); (3)(until C++11)constexprcomplex(constcomplex<float>&other);constexprcomplex(constcomplex<double>&other);(since C++11)Constructs the std::complex object. The standard explicit specializations (std::complex<float>, std::complex<double> and std::complex<longdouble>) have different constructor declarations from the main template.(until C++23)

1) Constructs the complex number from real part re and imaginary part im.

2) Copy constructor. Constructs the object with the copy of the contents of other.The copy constructors are implicitly declared in the standard explicit specializations.(until C++20)

3)

Converting constructor

. Constructs the object from a complex number of a different type.

The main template provides a converting constructor template, while each standard explicit specialization provides two non-template constructors for the two other standard explicit specializations.

The non-template constructors are converting constructors (i.e. non-explicit) if and only if the conversions of the real and imaginary parts are not narrowing.

(until C++23)For the main template, the expression inside explicit evaluates to false if and only if the

floating-point conversion rank

of T is greater than or equal to the floating-point conversion rank of X.

(since C++23)Parameters

re - the real part im - the imaginary part other - another complex number to use as source Notes

Since C++23, the copy constructor is required to be

trivial

in order to satisfy the

TriviallyCopyable

requirement, but implementations generally make it trivial in all modes.

See also