std::comple...ator-(unary)(3)

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

πŸ’… std::complex::operator+(unary), operator-(unary) πŸ’…

okay bestie, so this page lives in the C++ Standard Libary manual (yes that's the section name, we don't fix typos here, we respect the lore) β€” it's page std::comple...ator-(unary)(3), and it's all about the unary + and - for complex numbers. tiny page, huge main-character energy. let's go 🌸


✨ NAME ✨

std::complex::operator+(unary), operator-(unary) β€” literally just the unary plus and unary minus for std::complex. that's the whole vibe. πŸŽ€


✨ SYNOPSIS ✨

okay so here's the tea, and there are two eras of this β€” before C++20 and after, because constexpr said "let me in" 😌

template< class T >
std::complex<T> operator+( const std::complex<T>& val );          // (until C++20)
template< class T >
constexpr std::complex<T> operator+( const std::complex<T>& val ); // (since C++20)

that's (1) ⭐

template< class T >
std::complex<T> operator-( const std::complex<T>& val );          // (until C++20)
template< class T >
constexpr std::complex<T> operator-( const std::complex<T>& val ); // (since C++20)

and that one's (2) πŸ”₯


✨ DESCRIPTION ✨

so these implement the analogs of the unary arithmetic operators β€” but for complex numbers. like, the +x and -x you already know and love, except now the numbers have an imaginary part and honestly good for them πŸ¦‹

  1. Returns the value of its argument β€” no glow-up, no transformation, just... the same thing. it's giving "come as you are" πŸ’–
  2. Negates the argument β€” flips the whole thing around, real and imaginary alike πŸ™ˆ

✨ PARAMETERS ✨

  • val β€” the complex number argument, aka the little guy we're operating on 🫢

✨ RETURN VALUE ✨

  1. a copy of the argument, std::complex<T>(val) β€” yes, a copy, we do not touch the original πŸ’…
  2. negated argument, std::complex<T>(-val.real(), -val.imag()) β€” both parts get the minus treatment, no half measures ✨

✨ SEE ALSO ✨

these are the neighbors, the friend group of overloaded operators πŸ‘‘

  • operator+ β€” performs complex number arithmetic on two complex values or a complex and a scalar
  • operator- β€” performs complex number arithmetic on two complex values or a complex and a scalar
  • operator* (function template)
  • operator/

ngl if you're ever confused about which one you're looking at: unary means one argument, binary means two. this page is strictly unary. one (1) little complex number. periodt. πŸ’€

and that's the whole page, bestie β€” no cap, that's it, it's a short one. 🌈

βœ¨πŸ’– sourced from http://cppreference.com β€” dated 2024.06.10 β€” and that's the sign-off, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from