GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::operator== - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. unordered_map
  3. unordered_map
  4. operator==

最終更新日時: 2026年09月19日 21時31分51秒 (JST)
rotarymars が更新

履歴 編集

function template
<unordered_map>

std::operator==(C++11)

namespace std {
  template <class Key, class T, class Hash, class Pred, class Alloc>
  bool operator==(const unordered_map<Key,T,Hash,Pred,Alloc>& a,
                  const unordered_map<Key,T,Hash,Pred,Alloc>& b); // (1) C++11
  template <class Key, class T, class Hash, class Pred, class Alloc>
  constexpr bool operator==(const unordered_map<Key,T,Hash,Pred,Alloc>& a,
                  const unordered_map<Key,T,Hash,Pred,Alloc>& b); // (1) C++26
}

概要

unordered_map オブジェクトを等値比較する。

要件

  • a.key_eq() と b.key_eq() は同じふるまいをすること。
  • key_type の等値比較演算子(operator==)で等値と判定された 2 つのオブジェクトは、key_eq() でも等値と判定されること。

戻り値

以下の両方を満たす場合 true、そうでない場合 false。

  • a.size() == b.size() である。
  • 一方のコンテナの全ての要素が、他方のコンテナにも存在する。ここで、存在するとは、key_type の等値比較演算子(operator==)で等値と判定されるということである。

例外

投げない。

計算量

  • 平均: size() に対して線形時間
  • 最悪: size() に対して二乗時間

備考

  • 本関数は、コンテナ内の要素の比較に key_eq() で返されるキー比較用関数オブジェクトを使用しないことに注意。
  • 本関数は、標準コンテナの要件を満たさない。これは、標準コンテナの要件では operator!= が iterator と std::equal を用いて定義されているためである。しかし、本関数の戻り値は、両方のコンテナが同じ要素を保持しているという意味においては、標準コンテナと同様とも考えることができる。
  • この演算子によって、以下の演算子が使用可能になる (C++20):
    • operator!=

例

#include <iostream>
#include <unordered_map>

int main()
{
  std::unordered_map<int,char> um1;
  um1.insert(std::make_pair(10,'a'));
  um1.insert(std::make_pair(20,'b'));
  um1.insert(std::make_pair(30,'c'));


  std::unordered_map<int,char> um2;
  um2.insert(std::make_pair(30,'c'));
  um2.insert(std::make_pair(10,'a'));
  um2.insert(std::make_pair(20,'b'));

  std::cout << (um1 == um2) << std::endl;

  um2.insert(std::make_pair(40,'d'));

  std::cout << (um1 == um2) << std::endl;

  return 0;
}

出力

1
0

処理系

  • Clang: 9.0.1 ✅
  • GCC: ??
  • Visual C++: 2012 ✅

参照

  • P0809R0 Comparing Unordered Containers
  • P1614R2 The Mothership has Landed
    • C++20での三方比較演算子の追加と、関連する演算子の自動導出
  • P3372R3 constexpr containers and adaptors
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.