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

  • TUTORIALS
  • REFERENCE
  • ARTICLES
  • FORUM
  • C library:
  • <cassert> (assert.h)
  • <cctype> (ctype.h)
  • <cerrno> (errno.h)
  • <cfenv> (fenv.h)
  • <cfloat> (float.h)
  • <cinttypes> (inttypes.h)
  • <ciso646> (iso646.h)
  • <climits> (limits.h)
  • <clocale> (locale.h)

This view

  • Original page
  • New address

GeezerVison is showing cplusplus.com — std::operators (unordered_map)

  • TUTORIALS
  • REFERENCE
  • ARTICLES
  • FORUM

C++

  • Tutorials
  • Reference
  • Articles
  • Forum

Reference

  • C library:

    • <cassert> (assert.h)
    • <cctype> (ctype.h)
    • <cerrno> (errno.h)
    • C++11
      <cfenv> (fenv.h)
    • <cfloat> (float.h)
    • C++11
      <cinttypes> (inttypes.h)
    • <ciso646> (iso646.h)
    • <climits> (limits.h)
    • <clocale> (locale.h)
    • <cmath> (math.h)
    • <csetjmp> (setjmp.h)
    • <csignal> (signal.h)
    • <cstdarg> (stdarg.h)
    • C++11
      <cstdbool> (stdbool.h)
    • <cstddef> (stddef.h)
    • C++11
      <cstdint> (stdint.h)
    • <cstdio> (stdio.h)
    • <cstdlib> (stdlib.h)
    • <cstring> (string.h)
    • C++11
      <ctgmath> (tgmath.h)
    • <ctime> (time.h)
    • C++11
      <cuchar> (uchar.h)
    • <cwchar> (wchar.h)
    • <cwctype> (wctype.h)
  • Containers:

    • C++11
      <array>
    • <deque>
    • C++11
      <forward_list>
    • <list>
    • <map>
    • <queue>
    • <set>
    • <stack>
    • C++11
      <unordered_map>
    • C++11
      <unordered_set>
    • <vector>
  • Input/Output:

    • <fstream>
    • <iomanip>
    • <ios>
    • <iosfwd>
    • <iostream>
    • <istream>
    • <ostream>
    • <sstream>
    • <streambuf>
  • Multi-threading:

    • C++11
      <atomic>
    • C++11
      <condition_variable>
    • C++11
      <future>
    • C++11
      <mutex>
    • C++11
      <thread>
  • Other:

    • <algorithm>
    • <bitset>
    • C++11
      <chrono>
    • C++11
      <codecvt>
    • <complex>
    • <exception>
    • <functional>
    • C++11
      <initializer_list>
    • <iterator>
    • <limits>
    • <locale>
    • <memory>
    • <new>
    • <numeric>
    • C++11
      <random>
    • C++11
      <ratio>
    • C++11
      <regex>
    • <stdexcept>
    • <string>
    • C++11
      <system_error>
    • C++11
      <tuple>
    • C++11
      <type_traits>
    • C++11
      <typeindex>
    • <typeinfo>
    • <utility>
    • <valarray>

<unordered_map>

  • C++11
    unordered_map
  • C++11
    unordered_multimap

unordered_map

  • C++11
    unordered_map::~unordered_map
  • C++11
    unordered_map::unordered_map
  • member functions

    • C++11
      unordered_map::at
    • C++11
      unordered_map::begin
    • C++11
      unordered_map::bucket
    • C++11
      unordered_map::bucket_count
    • C++11
      unordered_map::bucket_size
    • C++11
      unordered_map::cbegin
    • C++11
      unordered_map::cend
    • C++11
      unordered_map::clear
    • C++11
      unordered_map::count
    • C++11
      unordered_map::emplace
    • C++11
      unordered_map::emplace_hint
    • C++11
      unordered_map::empty
    • C++11
      unordered_map::end
    • C++11
      unordered_map::equal_range
    • C++11
      unordered_map::erase
    • C++11
      unordered_map::find
    • C++11
      unordered_map::get_allocator
    • C++11
      unordered_map::hash_function
    • C++11
      unordered_map::insert
    • C++11
      unordered_map::key_eq
    • C++11
      unordered_map::load_factor
    • C++11
      unordered_map::max_bucket_count
    • C++11
      unordered_map::max_load_factor
    • C++11
      unordered_map::max_size
    • C++11
      unordered_map::operator[]
    • C++11
      unordered_map::operator=
    • C++11
      unordered_map::rehash
    • C++11
      unordered_map::reserve
    • C++11
      unordered_map::size
    • C++11
      unordered_map::swap
  • non-member overloads

    • C++11
      operators (unordered_map)
    • C++11
      swap (unordered_map)
  • Reference
  • <unordered_map>
  • unordered_map
  • operators
function template
<unordered_map>

std::operators (unordered_map)

equality (1)
template <class Key, class T, class Hash, class Pred, class Alloc>  bool operator== ( const unordered_map<Key,T,Hash,Pred,Alloc>& lhs,                    const unordered_map<Key,T,Hash,Pred,Alloc>& rhs );
inequality (2)
template <class Key, class T, class Hash, class Pred, class Alloc>  bool operator!= ( const unordered_map<Key,T,Hash,Pred,Alloc>& lhs,                    const unordered_map<Key,T,Hash,Pred,Alloc>& rhs );
Relational operators for unordered_map
These overloaded global operator functions perform the appropriate equality or inequality comparison operation between the unordered_map containers lhs and rhs.

The procedure for the equality comparison is as follows (stopping at any point if the procedure finds a conclusive answer):
  • First, the sizes are compared.
  • Then, each key in one of the containers is looked for in the other, and if found, their values are compared.

Note that the unordered_map::hash_function and unordered_map::key_eq objects are expected to have the same behavior in both lhs and rhs.

Parameters

lhs, rhs
unordered_map containers (to the left- and right-hand side of the operator, respectively), having both the same template parameters (Key, T, Hash, Pred and Alloc).

Return Value

true if the condition holds, and false otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// unordered_map comparisons
#include <iostream>
#include <string>
#include <unordered_map>

typedef std::unordered_map<std::string,std::string> stringmap;

int main ()
{
  stringmap a = { {"AAPL","Apple"}, {"MSFT","Microsoft"}, {"GOOG","Google"} };
  stringmap b = { {"MSFT","Microsoft"}, {"GOOG","Google"}, {"AAPL","Apple"} };
  stringmap c = { {"MSFT","Microsoft Corp."}, {"GOOG","Google Inc."}, {"AAPL","Apple Inc."} };

  if (a==b) std::cout << "a and b are equal\n";
  if (b!=c) std::cout << "b and c are not equal\n";

  return 0;
}

Output:
a and b are equal
b and c are not equal


Complexity

Average case: linear in size.
Worst case: quadratic in size.

Iterator validity

No changes.

See also

unordered_map::equal_range
Get range of elements with specific key (public member function)
unordered_map::operator=
Assign content (public member function)
Home page | Privacy policy
© cplusplus.com, 2000-2026 - All rights reserved - v3.3.4s
Spotted an error? contact us
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.