std::comple...ator-(unary)(3)
π 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 π¦
- Returns the value of its argument β no glow-up, no transformation, just... the same thing. it's giving "come as you are" π
- 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 β¨
- a copy of the argument,
std::complex<T>(val)β yes, a copy, we do not touch the original π - 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 scalaroperator-β performs complex number arithmetic on two complex values or a complex and a scalaroperator*(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
- 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