std::complex::real(3)

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

πŸ’… std::complex::real(3) β€” C++ Standard Library

okay so bestie, welcome to std::complex::real(3), straight out of the C++ Standard Library πŸ¦‹ this one's all about touching the real part of a complex number β€” getting it, setting it, the whole vibe. no cap, it's shorter than it looks, the synopsis is just doing the most with its column wrapping πŸ™ˆ


✨ SYNOPSIS ✨

heads up bestie, this synopsis is a whole mood board of overloads β€” every "until"/"since" tag is doing important work, so read them πŸ’–

🌸 primary template β€” std::complex<T>

T real() const;              (until C++14)
constexpr T real() const;    (since C++14)
void real( T value );        (until C++20)
constexpr void real( T value );  (since C++20)

πŸŽ€ specialization β€” std::complex<float>

float real() const;                  (until C++11)
constexpr float real() const;        (since C++11)
void real( float value );            (until C++20)
constexpr void real( float value );  (since C++20)

πŸ¦‹ specialization β€” std::complex<double>

(1) double real() const;                   (until C++11)
(2) constexpr double real() const;         (since C++11)
(1) void real( double value );             (until C++20)
(2) constexpr void real( double value );   (since C++20)

🌈 specialization β€” std::complex<long double>

(1) long double real() const;                    (until C++11)
(2) constexpr long double real() const;          (since C++11)
(1) void real( long double value );              (until C++20)
(2) constexpr void real( long double value );    (since C++20)

πŸ’œ DESCRIPTION

Accesses the real part of the complex number. that's it, that's the whole job, and it does it iconically ✨

  1. Returns the real part.
  2. Sets the real part to value.

πŸ“ PARAMETERS

  • value β€” the value to set the real part to πŸ’…

⭐ RETURN VALUE

  1. The real part of *this.
  2. (none) β€” yeah, the setter's giving nothing back, and honestly? valid.

🧚 NOTES

so in C++11, overload (1) in std::complex specializations used to be specified without the const qualifier 😭 but plot twist β€” in C++11, a constexpr specifier used in a non-static member function implies const, and thus the behavior is as if const is specified. the vibe check passed either way, no cap 🫢

πŸ”₯ Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. retroactive glow-ups, we love to see it πŸ‘‘

  • LWG 387, applied to C++98 β€” behavior as published: the real part could not be set directly; correct behavior: can be set directly via a new real overload πŸ’€βž‘οΈπŸ‘‘

πŸ‘‘ SEE ALSO

  • real β€” returns the real part (function template)
  • imag β€” accesses the imaginary part of the complex number (public member function)

and that's the page, bestie!! πŸŽ€πŸ’– go forth and set your real parts directly, you absolute main character 🌟

courtesy of http://cppreference.com, version 2024.06.10 β€” mwah, xoxo πŸ’…βœ¨

πŸ“¦ where this page comes from