complex_operator_cmp

complex_operator_cmp (복소수 비교 연산자)

두 복소수를 비교하는 함수예요. 스칼라 인자는 실수부가 인자와 같고 허수부가 0인 복소수처럼 취급돼요. C++14부터 constexpr이에요.

출처: cppreference

본문

<complex> 헤더에 정의되어 있고, 시그니처는 다음과 같아요.

template< class T >
bool operator==( const complex<T>& lhs, const complex<T>& rhs );

(1) (until C++14)

template< class T >
constexpr bool operator==( const complex<T>& lhs, const complex<T>& rhs );

(since C++14)

template< class T >
bool operator==( const complex<T>& lhs, const T& rhs );

(2) (until C++14)

template< class T >
constexpr bool operator==( const complex<T>& lhs, const T& rhs );

(since C++14)

template< class T >
bool operator==( const T& lhs, const complex<T>& rhs );

(3) (until C++14)

template< class T >
constexpr bool operator==( const T& lhs, const complex<T>& rhs );

(since C++14) (until C++20)

template< class T >
bool operator!=( const complex<T>& lhs, const complex<T>& rhs );

(4) (until C++14)

template< class T >
constexpr bool operator!=( const complex<T>& lhs, const complex<T>& rhs );

(since C++14) (until C++20)

template< class T >
bool operator!=( const complex<T>& lhs, const T& rhs );

(5) (until C++14)

template< class T >
constexpr bool operator!=( const complex<T>& lhs, const T& rhs );

(since C++14) (until C++20)

template< class T >
bool operator!=( const T& lhs, const complex<T>& rhs );

(6) (until C++14)

template< class T >
constexpr bool operator!=( const T& lhs, const complex<T>& rhs );

(since C++14) (until C++20)

두 복소수를 비교해요. 스칼라 인자는 실수부가 인자와 같고 허수부가 0으로 설정된 복소수처럼 취급돼요.

  • 1-3) lhs와 rhs를 같음으로 비교해요.
  • 4-6) lhs와 rhs를 다름으로 비교해요.

!= 연산자는 operator==에서 합성(synthesize)돼요.

(C++20부터)

매개변수 (Parameters)

  • lhs, rhs — 비교할 인자: 둘 다 복소수이거나 하나는 복소수, 하나는 일치하는 타입(float, double, long double)의 스칼라

반환값 (Return value)

  • 1-3) lhs의 각 부분이 rhs와 같으면 true, 그 외에는 false
  • 4-6) !(lhs == rhs)

예제 (Example)

이 코드를 실행해 봐요.

#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);
}

더 알아보기 (Learn more)

cppreference