Namensräume
Varianten
Aktionen

operator==,!=(std::complex)

Von cppreference.com
< cpp‎ | numeric‎ | complex
 
 
 
 
Definiert in der Header-Datei <complex>
(1)
template< class T >
bool operator==( const complex<T>& lhs, const complex<T>& rhs );
(bis C++14)
template< class T >
constexpr bool operator==( const complex<T>& lhs, const complex<T>& rhs );
(seit C++14)
(2)
template< class T >
bool operator==( const complex<T>& lhs, const T& rhs );
(bis C++14)
template< class T >
constexpr bool operator==( const complex<T>& lhs, const T& rhs );
(seit C++14)
(3)
template< class T >
bool operator==( const T& lhs, const complex<T>& rhs );
(bis C++14)
template< class T >
constexpr bool operator==( const T& lhs, const complex<T>& rhs );
(seit C++14)
(bis C++20)
(4)
template< class T >
bool operator!=( const complex<T>& lhs, const complex<T>& rhs );
(bis C++14)
template< class T >
constexpr bool operator!=( const complex<T>& lhs, const complex<T>& rhs );
(seit C++14)
(bis C++20)
(5)
template< class T >
bool operator!=( const complex<T>& lhs, const T& rhs );
(bis C++14)
template< class T >
constexpr bool operator!=( const complex<T>& lhs, const T& rhs );
(seit C++14)
(bis C++20)
(6)
template< class T >
bool operator!=( const T& lhs, const complex<T>& rhs );
(bis C++14)
template< class T >
constexpr bool operator!=( const T& lhs, const complex<T>& rhs );
(seit C++14)
(bis C++20)

Vergleicht zwei komplexe Zahlen. Skalarargumente werden als komplexe Zahlen mit einem Realteil gleich dem Argument und einem Imaginärteil von Null behandelt.

1-3) Vergleicht lhs und rhs auf Gleichheit.
4-6) Vergleicht lhs und rhs auf Ungleichheit.

Der Operator != wird aus operator== synthetisiert.

(seit C++20)

[bearbeiten] Parameter

lhs, rhs - die zu vergleichenden Argumente: entweder zwei komplexe Zahlen oder eine komplexe Zahl und ein Skalar des passenden Typs (float, double, long double)

[bearbeiten] Rückgabewert

1-3) true, wenn die jeweiligen Teile von lhs gleich rhs sind, false andernfalls.
4-6) !(lhs == rhs)

[bearbeiten] Beispiel

#include <complex>
 
int main()
{
    using std::operator""i; // or: using namespace std::complex_literals;
 
    static_assert(1.0i == 1.0i);
    static_assert(2.0i != 1.0i);
 
    constexpr std::complex z(1.0, 0.0);
    static_assert(z == 1.0);
    static_assert(1.0 == z);
    static_assert(2.0 != z);
    static_assert(z != 2.0);
}