std::complex::complex(3)
π std::complex::complex(3)
ok so first things first: this page lives in the C++ Standard Libary manual (yes, that's genuinely how it's spelled up top β she's iconic, leave her alone π) and it's all about std::complex::complex, the constructor. buckle up bestie, there are like four million overloads and we're meeting every single one π
β¨ NAME β¨
std::complex::complex β std::complex::complex.
that's it, that's the name. she's a constructor, her entire brand is existing. periodt π
πΈ SYNOPSIS πΈ
ngl the original synopsis arrived as one big column-smooshed soup (the columns got interleaved in transit π), so here it is all un-tangled β but every single declaration, every version tag and every (1)/(2)/(3) marker is still right here. no cap, nothing dropped π«Ά
π Primary template (std::complex<T>)
complex( const T& re = T(), const T& im = T() ); (until C++14)
constexpr complex( const T& re = T(), const T& im = T() ); (since C++14)
complex( const complex& other ); (until C++14)
constexpr complex( const complex& other ); (since C++14)
constexpr complex( const complex& other ) = default; (since C++23)
template< class X > complex( const complex<X>& other ); (until C++14)
template< class X > constexpr complex( const complex<X>& other ); (since C++14)
(until C++23)
template< class X > constexpr explicit(/* see below */)
complex( const complex<X>& other ); (since C++23)
π¦ Standard explicit specialization std::complex<float>
complex( float re = 0.0f, float im = 0.0f ); (until C++11)
constexpr complex( float re = 0.0f, float im = 0.0f ); (since C++11)
constexpr complex( const complex<float>& other ) = default; (since C++20)
explicit complex( const complex<double>& other ); (until C++11)
explicit complex( const complex<long double>& other ); (until C++11)
constexpr explicit complex( const complex<double>& other ); (since C++11)
constexpr explicit complex( const complex<long double>& other ); (since C++11)
π Standard explicit specialization std::complex<double>
complex( double re = 0.0, double im = 0.0 ); (until C++11)
constexpr complex( double re = 0.0, double im = 0.0 ); (since C++11)
constexpr complex( const complex<double>& other ) = default; (since C++20)
complex( const complex<float>& other ); (until C++11)
explicit complex( const complex<long double>& other ); (until C++11)
constexpr complex( const complex<float>& other ); (since C++11)
constexpr explicit complex( const complex<long double>& other ); (since C++11)
β Standard explicit specialization std::complex<long double>
complex( long double re = 0.0L, long double im = 0.0L ); (until C++11)
constexpr complex( long double re = 0.0L,
long double im = 0.0L ); (since C++11)
constexpr complex( const complex<long double>& other ) = default; (since C++20)
complex( const complex<float>& other ); (until C++11)
complex( const complex<double>& other ); (until C++11)
constexpr complex( const complex<float>& other ); (since C++11)
constexpr complex( const complex<double>& other ); (since C++11)
and the (1) (2) (3) markers you'll see floating around below mean:
- (1) β the "make a complex out of a real part and an imaginary part" one π
- (2) β the copy constructor π
- (3) β the converting constructor π
π DESCRIPTION π
Constructs the std::complex object. that's the whole job bestie, and she does it flawlessly β¨
The standard explicit specializations (std::complex<float>, std::complex<double> and std::complex<long double>) 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.
(until C++23)
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. (read that twice, it's the whole vibe check π₯)
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. (so like, the standard finally caught up to what everyone was already doing, we love a glow-up π)
π«Ά SEE ALSO π«Ά
operator=β assigns the contents (public member function)operator""ifoperator""iβ astd::complexliteral representing purely imaginary numberoperator""ilβ (function) (C++14)- C documentation for
CMPLX
ok that's the whole page, you ate that π stay hydrated, go construct some complex numbers responsibly, and remember: narrowing conversions are not the move unless the standard says so πΈ
sign-off corner: this was brought to you byhttp://cppreference.com, dated2024.06.10, and filed understd::complex::complex(3)β mwah, love u, bye π¦π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms