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

履歴 編集

function template
<utility>

std::operator==

namespace std {
  template <class T1, class T2>
  bool operator==(const pair<T1, T2>& x, const pair<T1, T2>& y);           // (1) C++03

  template <class T1, class T2>
  constexpr bool operator==(const pair<T1, T2>& x, const pair<T1, T2>& y); // (1) C++14

  template <class T1, class T2>
  struct pair {
    friend constexpr bool operator==(const pair&, const pair&) = default; // (1) C++20

    friend constexpr bool operator==(const pair& x, const pair& y)        // (2) C++20
        requires (is_reference_v<T1> || is_reference_v<T2>);
  };
}

概要

2つのpairの等値比較を行う

戻り値

return x.first == y.first && x.second == y.second;

備考

  • この演算子により、以下の演算子が使用可能になる (C++20):
    • operator!=

#include <iostream>
#include <utility>
#include <string>

int main()
{
  std::pair<int, std::string> p1(1, "aaa");
  std::pair<int, std::string> p2(1, "aaa");
  std::pair<int, std::string> p3(2, "bbb");

  std::cout << std::boolalpha;
  std::cout << (p1 == p2) << std::endl;
  std::cout << (p1 == p3) << std::endl;
}

出力

true
false

参照