std::complex::operator=(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… std::complex::operator=(3) πŸ’…

okay so bestie, welcome to the std::complex::operator= page from the C++ Standard Libary manual πŸ’– this is the assignment-operator corner of std::complex, and it's giving β€œnew value, new me” energy. no cap, the whole page is about stuffing fresh values into your complex number ✨

🌸 NAME 🌸

std::complex::operator= β€” literally std::complex::operator= πŸ’…

✨ Synopsis ✨

All specializations

  • complex& operator=( const complex& cx ); β€” until C++20
  • constexpr complex& operator=( const complex& cx ); β€” since C++20
  • 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>

  • complex& operator=( const T& x ); β€” (1), until C++20
  • constexpr complex& operator=( const T& x ); β€” (2), since C++20

Specializations for standard floating-point types complex<F> (until C++23)

  • complex& operator=( F x ); β€” (3), until C++20
  • constexpr complex& operator=( F x ); β€” (3), since C++20

okay so what's the actual assignment tea? Assigns new values to the contents. that's the vibe 🫢

  • 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.

πŸŽ€ Parameters πŸŽ€

  • x β€” value to assign
  • cx β€” complex value to assign

🎁 Return value 🎁

*this β€” that's the return, bestie. It hands you back *this πŸ’–

πŸ“ Notes πŸ“

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

🩹 Defect reports 🩹

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

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

πŸ‘€ See also πŸ‘€

  • constructor β€” constructs a complex number (public member function)
  • operator""if, operator""i, operator""il β€” a std::complex literal representing purely imaginary number (function) (C++14)

that's the whole page, bestie 🫢 source/version/date check: http://cppreference.com, 2024.06.10, and this is std::complex::operator=(3) β€” periodt πŸ’…

πŸ“¦ where this page comes from