最終更新日時(UTC):
が更新

履歴 編集

function template
<complex>

std::operator!=

namespace std {
  // operator==により、以下の演算子が使用可能になる (C++20)
  template <class T>
  bool operator!=(const complex<T>& lhs,
                  const complex<T>& rhs);           // (1) C++03
  template <class T>
  constexpr bool operator!=(const complex<T>& lhs,
                            const complex<T>& rhs); // (1) C++14

  template <class T>
  bool operator!=(const complex<T>& lhs,
                  const T& rhs);                    // (2) C++03
  template <class T>
  constexpr bool operator!=(const complex<T>& lhs,
                            const T& rhs);          // (2) C++14

  template <class T>
  bool operator==(const T& lhs,
                  const complex<T>& rhs);           // (3) C++03
  template <class T>
  constexpr bool operator==(const T& lhs,
                            const complex<T>& rhs); // (3) C++14
}

概要

非等値比較を行う。

戻り値

lhs.real() != rhs.real() || lhs.imag() != rhs.imag()

備考

引数の型が const T& の場合、虚部(imag())は T()、あるいは、0.0 とみなされる。

#include <iostream>
#include <complex>

int main()
{
  std::complex<double> c1(1.0, 2.0);
  std::complex<double> c2(1.0, 4.0);
  std::cout << std::boolalpha;
  std::cout << c1 << " != " << c1 << ":" << (c1 != c1) << std::endl;
  std::cout << c1 << " != " << c2 << ":" << (c1 != c2) << std::endl;
  std::cout << c1 << " != " << 1.0 << ":" << (c1 != 1.0) << std::endl;
  std::cout << 4.0 << " != " << c2 << ":" << (4.0 != c2) << std::endl;
}

出力

(1,2) != (1,2):false
(1,2) != (1,4):true
(1,2) != 1:true
4 != (1,4):true

関連項目

名前 説明
operator== 等値比較を行う。
real 実部を取得、あるいは、設定する。(メンバ関数)
imag 虚部を取得、あるいは、設定する。(メンバ関数)

参照