C++

'std::​unordered_map' Is Not a Member of 'std' Fix

std::unordered_map lives in one header, <unordered_map>, and in language modes from C++11 onward. Miss the header and the name is not a member of std, with a note naming the header to add; compile in an older mode and the library headers refuse with a #error first - and among the headers probed in this guide's sweep, none rescues the name at all: the title error stays exactly as it was.

Written November 29, 2026 · Tested with GCC 13.3.0 · 26 min read

By the end of this guide
  • The rule underneath: one header, C++11 or later
  • The first failure: no &lt;unorderedmap&gt; include
  • The same failure at namespace scope: does not name a template type
  • The second failure: &lt;unorderedmap&gt; included, compiled as C++98

Written November 29, 2026

Tested with GCC 13.3.0

What this guide is

The error on a std::unordered_map name means the compiler has no unordered_map name inside std to find. Inside a function, GCC words it exactly as this guide's title promises: 'unordered_map' is not a member of 'std'. The common cause is a missing include: nothing in the file included <unordered_map>, the header that declares the name, so the lookup fails at the first use. The second cause is the language mode: std::unordered_map is since C++11, so a file compiled in an older mode gets no std::unordered_map either - and that shape announces itself differently, with a #error from inside the library headers before the same not-a-member errors follow.

The wording also changes with where the failing name sits. At namespace scope, where the name is used as a type for a variable declaration, GCC reports 'unordered_map' in namespace 'std' does not name a template type instead - note the word "template": this name is a class template, and the namespace-scope wording says so, where the same fault on a non-template name is worded as "does not name a type". Both wordings appear below; they are one fault - the name is absent - read at two different positions in the file.

Unlike some other missing names, this error does carry its remedy with it: GCC attaches a note to the std::unordered_map error naming the header to add - 'std::unordered_map' is defined in header '<unordered_map>'; did you forget to '#include <unordered_map>'? Read the note before anything else in the cascade, because it is the diagnosis and the fix in one line. And among the headers probed in the sweep below, no neighboring header rescues this name at all - not even partially: the title error persists unchanged in every sweep program. The fix stays direct either way: #include <unordered_map> in the file itself, plus a language mode of C++11 or later.

The rule underneath: one header, C++11 or later

The std::unordered_map page dates the type: the class template unordered_map is since C++11, defined in header <unordered_map>, an associative container that contains key-value pairs with unique keys, organized into buckets by the hash of the key, with no particular order to its elements. Its default template arguments name the two requirements a key type must meet: Hash defaults to std::hash<Key> and KeyEqual defaults to std::equal_to<Key> - the hash requirement is the boundary one of the neighboring-error sections below crosses. There is no C++03 form of std::unordered_map: the type arrived with the 2011 standard.

The header page shows what the header declares, all in namespace std and since C++11 unless a later date is shown: the unordered_map and unordered_multimap class templates and their comparison and swap functions. The member functions this guide's programs use carry the same date on their own pages: operator[] is since C++11 and returns a reference to the value mapped to a key, inserting it if it does not already exist - and, as the operator[] page states in its notes, operator[] is non-const because it inserts the key if it does not exist, so on a const map at may be used instead. The at page gives at since C++11 as well: it returns a reference to the mapped value for a key, with bounds checking, and throws std::out_of_range if no such element exists; it has a const overload, which is why it works where operator[] does not. size returns the number of elements and count returns the number of elements matching a specific key - for a map with unique keys, 1 when the key is present and 0 when it is not. So a std::unordered_map name needs both conditions at once: the header included, so the declarations are in the file, and a language mode of C++11 or later, so the header is allowed to declare them.

The first failure: no <unordered_map> include

This program uses std::unordered_map<int, int> with integer keys and includes no header at all - deliberately, because a companion header would be its own possible rescue, and the sweep below measures each candidate header on its own instead. Integer keys also keep the headline clean: a std::string key would need <string> of its own, and that header would be a companion in the file before the map error is even reached:

C++
int main() {
    std::unordered_map<int, int> m;
    m[1] = 10;
    return m.at(1) == 10 ? 0 : 1;
}
Terminal
$ g++ -std=c++11 p1_fail_no_include.cpp -o p1_fail_no_include
p1_fail_no_include.cpp: In function 'int main()':
p1_fail_no_include.cpp:2:10: error: 'unordered_map' is not a member of 'std'
    2 |     std::unordered_map<int, int> m;
      |          ^~~~~~~~~~~~~
p1_fail_no_include.cpp:1:1: note: 'std::unordered_map' is defined in header '<unordered_map>'; did you forget to '#include <unordered_map>'?
  +++ |+#include <unordered_map>
    1 | int main() {
p1_fail_no_include.cpp:2:24: error: expected primary-expression before 'int'
    2 |     std::unordered_map<int, int> m;
      |                        ^~~
p1_fail_no_include.cpp:3:5: error: 'm' was not declared in this scope
    3 |     m[1] = 10;
      |     ^

Read the note first: it sits directly under the title error and names the header, so this shape diagnoses itself - the include is missing, and the note says which one. The errors that follow are the cascade from that one absence. expected primary-expression before 'int' is the compiler trying to read std::unordered_map<int, int> as something other than a template name, because the template name is not there. And 'm' was not declared in this scope is fallout: the declaration failed, so the variable does not exist where it is used on the next line. The language mode here is already C++11, so the mode is not the problem in this shape; the missing header is.

The same failure at namespace scope: does not name a template type

The same missing include at namespace scope is worded differently. This program declares the map as a file-scope variable, still with no header:

C++
std::unordered_map<int, int> g_m;

int main() {
    g_m[1] = 10;
    return g_m.at(1) == 10 ? 0 : 1;
}
Terminal
$ g++ -std=c++11 p1b_fail_scope.cpp -o p1b_fail_scope
p1b_fail_scope.cpp:1:6: error: 'unordered_map' in namespace 'std' does not name a template type
    1 | std::unordered_map<int, int> g_m;
      |      ^~~~~~~~~~~~~
p1b_fail_scope.cpp:1:1: note: 'std::unordered_map' is defined in header '<unordered_map>'; did you forget to '#include <unordered_map>'?
  +++ |+#include <unordered_map>
    1 | std::unordered_map<int, int> g_m;
p1b_fail_scope.cpp: In function 'int main()':
p1b_fail_scope.cpp:4:5: error: 'g_m' was not declared in this scope
    4 |     g_m[1] = 10;
      |     ^~~

Same fault, different first line: where the name is used as a type outside a function, GCC says it does not name a template type; where it is used inside a function, GCC says it is not a member of std. The wording is worth recognizing exactly, because "does not name a template type" is this name's namespace-scope form - a non-template name in the same position is reported as "does not name a type", without the word "template". The header note appears here too, unchanged, naming <unordered_map> as the remedy, and the undeclared-variable error follows inside main exactly as in the function-scope shape. Recognize either wording as the missing-include shape.

The second failure: <unordered_map> included, compiled as C++98

The same use of the library with the header included still fails when the language mode is older than the library - and here the first diagnostic is not the title error at all, but a refusal from inside the library headers:

C++
#include <unordered_map>
#include <iostream>

int main() {
    std::unordered_map<int, int> m;
    m[1] = 10;
    m[2] = 20;
    std::cout << m.at(1) << " " << m.at(2) << "\n";
    return 0;
}
Terminal
$ g++ -std=c++98 p2_included.cpp -o p2_cpp98
In file included from /usr/include/c++/13/unordered_map:37,
                 from p2_included.cpp:1:
/usr/include/c++/13/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
   32 | #error This file requires compiler and library support \
      |  ^~~~~
p2_included.cpp: In function 'int main()':
p2_included.cpp:5:10: error: 'unordered_map' is not a member of 'std'
    5 |     std::unordered_map<int, int> m;
      |          ^~~~~~~~~~~~~
p2_included.cpp:5:10: note: 'std::unordered_map' is only available from C++11 onwards
p2_included.cpp:5:24: error: expected primary-expression before 'int'
    5 |     std::unordered_map<int, int> m;
      |                        ^~~
p2_included.cpp:6:5: error: 'm' was not declared in this scope; did you mean 'tm'?
    6 |     m[1] = 10;
      |     ^
      |     tm

The #error is the tell: it comes from the library's own headers - from bits/c++0x_warning.h, included from <unordered_map> - names the 2011 standard as the requirement, and names the remedy - enable -std=c++11 or -std=gnu++11. The include is present and correct, and adding it again changes nothing; the mode is the fault. This shape also carries a different note from the missing-include shape: under the title error here, the note reads 'std::unordered_map' is only available from C++11 onwards - not the "did you forget to include" note, because the include is already there and the mode is what is missing. The not-a-member errors still follow underneath, because with the header's contents withheld the names are absent exactly as in the missing-include shape - which is why reading only the later errors misleads: scroll to the first diagnostic, and if it is this #error, the compile line is what to fix. At -std=c++03 this exact program fails identically, line for line - same #error, same note, same not-a-member errors - so both probed pre-C++11 modes produce this one shape. Raise the mode and the same file compiles unchanged: at -std=c++11 it compiles and prints 10 20.

The header sweep: no rescue among the headers probed

A missing standard name is sometimes rescued by accident, when another header happens to include the one that declares it. For std::unordered_map the sweep in this guide finds no rescue at all among the headers probed. Each sweep program uses the map with one candidate header as its only include, and no other header - a second include would be its own possible rescue and would spoil the measurement. This program, with <string> in that position and still no <unordered_map>, fails with exactly the missing-include shape:

C++
#include <string>

int main() {
    std::unordered_map<int, int> m;
    m[1] = 10;
    return m.at(1) == 10 ? 0 : 1;
}
Terminal
$ g++ -std=c++11 sweep_string.cpp -o sweep_string
sweep_string.cpp: In function 'int main()':
sweep_string.cpp:4:10: error: 'unordered_map' is not a member of 'std'
    4 |     std::unordered_map<int, int> m;
      |          ^~~~~~~~~~~~~
sweep_string.cpp:2:1: note: 'std::unordered_map' is defined in header '<unordered_map>'; did you forget to '#include <unordered_map>'?
    1 | #include <string>
  +++ |+#include <unordered_map>
    2 | 
sweep_string.cpp:4:24: error: expected primary-expression before 'int'
    4 |     std::unordered_map<int, int> m;
      |                        ^~~
sweep_string.cpp:5:5: error: 'm' was not declared in this scope; did you mean 'tm'?
    5 |     m[1] = 10;
      |     ^
      |     tm

Read what did not change. The title error is still there, word for word: the compiler still says unordered_map is not a member of std, still attaches the same header note naming <unordered_map>, and the same cascade follows. In the sweep above, no candidate header declared the name, even as a forward declaration - so there is no half-rescued incomplete-type state for this name among the headers probed, unlike names where a probed neighbor declares without defining. The same program was compiled with each of <iostream>, <vector>, <algorithm>, <array> and <utility> as the only candidate header, at C++11: every one fails with the same title error, the same header note, and the same cascade shape. So of the six headers probed in place of <unordered_map>, all six leave the title error in place and none produces a working program - among the headers probed, the name simply does not arrive by accident. That makes the repair the direct one: include <unordered_map> itself in every file that names std::unordered_map.

The fix: include <unordered_map> and compile at C++11 or later

Both halves together - the header included, the mode at C++11 - and the library is fully usable. This program inserts two string keys with operator[], reads them back with .at(), and prints the map's size and a count lookup:

C++
#include <unordered_map>
#include <iostream>
#include <string>

int main() {
    std::unordered_map<std::string, int> scores;
    scores["ada"] = 36;
    scores["grace"] = 85;
    std::cout << scores.at("ada") << " " << scores.at("grace") << "\n";
    std::cout << "size " << scores.size() << "\n";
    std::cout << "count ada " << scores.count("ada") << "\n";
    return 0;
}
Terminal
$ g++ -std=c++11 p4_fix.cpp -o p4_fix
$ ./p4_fix
36 85
size 2
count ada 1

Every name that failed before now resolves. operator[] inserts each key and stores its value - 36 under "ada" and 85 under "grace" - and the two .at() calls read those values back by key, printing 36 85. The second line is the size: the map holds 2 elements, matching the two keys inserted. The third line is the count: count("ada") returns 1, because this map's keys are unique and "ada" is present. Nothing in this program prints the map by iterating over it, deliberately: the elements of an unordered map are not sorted in any particular order, so iteration order is not a value a reader can check - every printed value here is looked up by key, counted, or sized, and is fully determined by the values in the program, so any other output means the program, not the machine, differs.

Neighboring error: operator[] on a const map

Once <unordered_map> is included and the mode is right, a const map produces a different error on a different subject. operator[] can insert a missing key, so it is non-const - it cannot be called on a const map. Reading a value with scores["ada"] on a const map fails like this:

C++
#include <unordered_map>
#include <string>

int main() {
    const std::unordered_map<std::string, int> scores{{"ada", 36}};
    return scores["ada"] == 36 ? 0 : 1;
}
Terminal
$ g++ -std=c++11 p5_neighbour_const_subscript.cpp -o p5_neighbour_const_subscript
p5_neighbour_const_subscript.cpp: In function 'int main()':
p5_neighbour_const_subscript.cpp:6:24: error: passing 'const std::unordered_map<std::__cxx11::basic_string<char>, int>' as 'this' argument discards qualifiers [-fpermissive]
    6 |     return scores["ada"] == 36 ? 0 : 1;
      |                        ^
In file included from /usr/include/c++/13/unordered_map:41,
                 from p5_neighbour_const_subscript.cpp:1:
/usr/include/c++/13/bits/unordered_map.h:990:7: note:   in call to 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&&) [with _Key = std::__cxx11::basic_string<char>; _Tp = int; _Hash = std::hash<std::__cxx11::basic_string<char> >; _Pred = std::equal_to<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, int> >; mapped_type = int; key_type = std::__cxx11::basic_string<char>]'
  990 |       operator[](key_type&& __k)
      |       ^~~~~~~~

The contrast separates the two errors cleanly. This error says nothing about a missing name - the include and the mode are already right, the type was found, and the failure is the call itself: passing the const map as the this argument discards qualifiers, because the only operator[] overloads are non-const. The title error names unordered_map as not a member of std, because the type was never there to be used. The repair here is to change the access, not the include: .at("ada") has a const overload and reads the value without any power to insert - scores.at("ada") is the read this program was reaching for, and it is also the read to prefer whenever a missing key should be an error rather than a silent insertion.

Neighboring error: a custom key type with no std::hash

The other neighboring fault keeps the right include, the right mode and a well-formed-looking key type - and still fails, inside the library headers. An unordered map hashes its keys, and its Hash template argument defaults to std::hash<Key>. A custom key type that defines equality but provides no std::hash specialization gives the default hash nothing to call:

C++
#include <unordered_map>

struct Key {
    int id;
    bool operator==(const Key& other) const { return id == other.id; }
};

int main() {
    std::unordered_map<Key, int> m;
    m[Key{1}] = 10;
    return m.at(Key{1}) == 10 ? 0 : 1;
}
Terminal
$ g++ -std=c++11 p6_neighbour_no_hash.cpp -o p6_neighbour_no_hash
p6_neighbour_no_hash.cpp: In function 'int main()':
p6_neighbour_no_hash.cpp:9:34: error: use of deleted function 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = Key; _Tp = int; _Hash = std::hash<Key>; _Pred = std::equal_to<Key>; _Alloc = std::allocator<std::pair<const Key, int> >]'
    9 |     std::unordered_map<Key, int> m;
      |                                  ^
In file included from /usr/include/c++/13/unordered_map:41,
                 from p6_neighbour_no_hash.cpp:1:
/usr/include/c++/13/bits/unordered_map.h:148:7: note: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = Key; _Tp = int; _Hash = std::hash<Key>; _Pred = std::equal_to<Key>; _Alloc = std::allocator<std::pair<const Key, int> >]' is implicitly deleted because the default definition would be ill-formed:
  148 |       unordered_map() = default;
      |       ^~~~~~~~~~~~~
/usr/include/c++/13/bits/unordered_map.h:148:7: error: use of deleted function 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = Key; _Value = std::pair<const Key, int>; _Alloc = std::allocator<std::pair<const Key, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<Key>; _Hash = std::hash<Key>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]'
In file included from /usr/include/c++/13/bits/unordered_map.h:33:
/usr/include/c++/13/bits/hashtable.h:530:7: note: 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::_Hashtable() [with _Key = Key; _Value = std::pair<const Key, int>; _Alloc = std::allocator<std::pair<const Key, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<Key>; _Hash = std::hash<Key>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed:
  530 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/13/bits/hashtable.h:530:7: error: use of deleted function 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = Key; _Value = std::pair<const Key, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<Key>; _Hash = std::hash<Key>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]'
In file included from /usr/include/c++/13/bits/hashtable.h:35:
/usr/include/c++/13/bits/hashtable_policy.h:1701:7: note: 'std::__detail::_Hashtable_base<_Key, _Value, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _Traits>::_Hashtable_base() [with _Key = Key; _Value = std::pair<const Key, int>; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<Key>; _Hash = std::hash<Key>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _Traits = std::__detail::_Hashtable_traits<true, false, true>]' is implicitly deleted because the default definition would be ill-formed:
 1701 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable_policy.h:1701:7: error: use of deleted function 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = Key; _Value = std::pair<const Key, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<Key>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]'
/usr/include/c++/13/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hashtable_ebo_helper<_Nm, _Tp, true>::_Hashtable_ebo_helper() [with int _Nm = 1; _Tp = std::hash<Key>]':
/usr/include/c++/13/bits/hashtable_policy.h:1301:7:   required from here
/usr/include/c++/13/bits/hashtable_policy.h:1218:49: error: use of deleted function 'std::hash<Key>::hash()'
 1218 |       _Hashtable_ebo_helper() noexcept(noexcept(_Tp())) : _Tp() { }
      |                                                 ^~~~~
In file included from /usr/include/c++/13/bits/hashtable_policy.h:35:
/usr/include/c++/13/bits/functional_hash.h:102:12: note: 'std::hash<Key>::hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/13/bits/functional_hash.h:102:12: error: no matching function for call to 'std::__hash_enum<Key, false>::__hash_enum()'
/usr/include/c++/13/bits/functional_hash.h:83:7: note: candidate: 'std::__hash_enum<_Tp, <anonymous> >::__hash_enum(std::__hash_enum<_Tp, <anonymous> >&&) [with _Tp = Key; bool <anonymous> = false]'
   83 |       __hash_enum(__hash_enum&&);
      |       ^~~~~~~~~~~
/usr/include/c++/13/bits/functional_hash.h:83:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/13/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = Key; bool <anonymous> = false]' is private within this context
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/13/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/13/bits/hashtable_policy.h:1301:7: note: 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_Hash_code_base() [with _Key = Key; _Value = std::pair<const Key, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<Key>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true]' is implicitly deleted because the default definition would be ill-formed:
 1301 |       _Hash_code_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable_policy.h:1301:7: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<Key>, true>::~_Hashtable_ebo_helper()'
/usr/include/c++/13/bits/hashtable_policy.h:1215:12: note: 'std::__detail::_Hashtable_ebo_helper<1, std::hash<Key>, true>::~_Hashtable_ebo_helper()' is implicitly deleted because the default definition would be ill-formed:
 1215 |     struct _Hashtable_ebo_helper<_Nm, _Tp, true>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable_policy.h:1215:12: error: use of deleted function 'std::hash<Key>::~hash()'
/usr/include/c++/13/bits/functional_hash.h:102:12: note: 'std::hash<Key>::~hash()' is implicitly deleted because the default definition would be ill-formed:
  102 |     struct hash : __hash_enum<_Tp>
      |            ^~~~
/usr/include/c++/13/bits/functional_hash.h:102:12: error: 'std::__hash_enum<_Tp, <anonymous> >::~__hash_enum() [with _Tp = Key; bool <anonymous> = false]' is private within this context
/usr/include/c++/13/bits/functional_hash.h:84:7: note: declared private here
   84 |       ~__hash_enum();
      |       ^
/usr/include/c++/13/bits/hashtable_policy.h:1701:7: error: use of deleted function 'std::__detail::_Hash_code_base<Key, std::pair<const Key, int>, std::__detail::_Select1st, std::hash<Key>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()'
 1701 |       _Hashtable_base() = default;
      |       ^~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable_policy.h:1279:12: note: 'std::__detail::_Hash_code_base<Key, std::pair<const Key, int>, std::__detail::_Select1st, std::hash<Key>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()' is implicitly deleted because the default definition would be ill-formed:
 1279 |     struct _Hash_code_base
      |            ^~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable_policy.h:1279:12: error: use of deleted function 'std::__detail::_Hashtable_ebo_helper<1, std::hash<Key>, true>::~_Hashtable_ebo_helper()'
/usr/include/c++/13/bits/hashtable.h:530:7: error: use of deleted function 'std::__detail::_Hashtable_base<Key, std::pair<const Key, int>, std::__detail::_Select1st, std::equal_to<Key>, std::hash<Key>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, false, true> >::~_Hashtable_base()'
  530 |       _Hashtable() = default;
      |       ^~~~~~~~~~
/usr/include/c++/13/bits/hashtable_policy.h:1658:12: note: 'std::__detail::_Hashtable_base<Key, std::pair<const Key, int>, std::__detail::_Select1st, std::equal_to<Key>, std::hash<Key>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, false, true> >::~_Hashtable_base()' is implicitly deleted because the default definition would be ill-formed:
 1658 |     struct _Hashtable_base
      |            ^~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable_policy.h:1658:12: error: use of deleted function 'std::__detail::_Hash_code_base<Key, std::pair<const Key, int>, std::__detail::_Select1st, std::hash<Key>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, true>::~_Hash_code_base()'
/usr/include/c++/13/bits/hashtable.h:530:7: error: use of deleted function 'constexpr std::_Enable_default_constructor<false, _Tag>::_Enable_default_constructor() [with _Tag = std::__detail::_Hash_node_base]'
  530 |       _Hashtable() = default;
      |       ^~~~~~~~~~
In file included from /usr/include/c++/13/bits/hashtable.h:36:
/usr/include/c++/13/bits/enable_special_members.h:113:15: note: declared here
  113 |     constexpr _Enable_default_constructor() noexcept = delete;
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable.h: In instantiation of 'std::_Hashtable<_Key, _Value, _Alloc, _ExtractKey, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits>::~_Hashtable() [with _Key = Key; _Value = std::pair<const Key, int>; _Alloc = std::allocator<std::pair<const Key, int> >; _ExtractKey = std::__detail::_Select1st; _Equal = std::equal_to<Key>; _Hash = std::hash<Key>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>]':
/usr/include/c++/13/bits/unordered_map.h:109:11:   required from here
/usr/include/c++/13/bits/hashtable.h:1610:5: error: use of deleted function 'std::__detail::_Hashtable_base<Key, std::pair<const Key, int>, std::__detail::_Select1st, std::equal_to<Key>, std::hash<Key>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Hashtable_traits<true, false, true> >::~_Hashtable_base()'
 1610 |     }
      |     ^
/usr/include/c++/13/bits/hashtable.h:1602:21: error: static assertion failed: Cache the hash code or qualify your functors involved in hash code and bucket index computation with noexcept
 1602 |       static_assert(noexcept(declval<const __hash_code_base_access&>()
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1603 |                         ._M_bucket_index(declval<const __node_value_type&>(),
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1604 |                                          (std::size_t)0)),
      |                                          ~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable.h:1602:21: note: 'false' evaluates to false
/usr/include/c++/13/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::__hash_code std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_M_hash_code(const _Key&) const [with _Key = Key; _Value = std::pair<const Key, int>; _ExtractKey = std::__detail::_Select1st; _Hash = std::hash<Key>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true; __hash_code = long unsigned int]':
/usr/include/c++/13/bits/hashtable_policy.h:840:45:   required from 'std::__detail::_Map_base<_Key, std::pair<const _Key, _Val>, _Alloc, std::__detail::_Select1st, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>::mapped_type& std::__detail::_Map_base<_Key, std::pair<const _Key, _Val>, _Alloc, std::__detail::_Select1st, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>::operator[](key_type&&) [with _Key = Key; _Val = int; _Alloc = std::allocator<std::pair<const Key, int> >; _Equal = std::equal_to<Key>; _Hash = std::hash<Key>; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>; mapped_type = int; key_type = Key]'
/usr/include/c++/13/bits/unordered_map.h:991:20:   required from 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&&) [with _Key = Key; _Tp = int; _Hash = std::hash<Key>; _Pred = std::equal_to<Key>; _Alloc = std::allocator<std::pair<const Key, int> >; mapped_type = int; key_type = Key]'
p6_neighbour_no_hash.cpp:10:13:   required from here
/usr/include/c++/13/bits/hashtable_policy.h:1308:23: error: static assertion failed: hash function must be invocable with an argument of key type
 1308 |         static_assert(__is_invocable<const _Hash&, const _Key&>{},
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/hashtable_policy.h:1308:23: note: 'std::__is_invocable<const std::hash<Key>&, const Key&>()' evaluates to false
/usr/include/c++/13/bits/hashtable_policy.h:1310:25: error: no match for call to '(const std::hash<Key>) (const Key&)'
 1310 |         return _M_hash()(__k);
      |                ~~~~~~~~~^~~~~

Nothing in this outcome says a name is missing - the include and the mode are right, and the failure is the hash, not the map name. The trace is long because the refusal repeats through the hashtable machinery underneath the map, but the lines to recognize are at its end: the static assertion hash function must be invocable with an argument of key type, with the note that std::__is_invocable<const std::hash<Key>&, const Key&>() evaluates to false, and the line under it, no match for call to '(const std::hash<Key>) (const Key&)'. Higher in the trace the same fault appears as a chain of deleted functions, starting with the map's own constructor - use of deleted function 'std::unordered_map<...>::unordered_map()' - because the default std::hash<Key> is itself deleted for a key type it does not know. The repair is in the key type's support, not the headers: provide a std::hash<Key> specialization that returns a hash of the key's identifying fields - here, a hash of id - or pass a custom hash type as the map's third template argument. When an unordered map program fails with a static assertion about the hash function from inside the library headers, read it as a key-type fault in the program - the required from here lines in the trace point back at the map's own lines.

Decision summary

  • The first errors are 'unordered_map' is not a member of 'std', with a note under it saying 'std::unordered_map' is defined in header '<unordered_map>'; did you forget to '#include <unordered_map>'? and no #error above them: the header is missing - add #include <unordered_map>, exactly as the note says; every later error in the cascade traces to the absent name.
  • The first error is 'unordered_map' in namespace 'std' does not name a template type, with the same header note under it: the same missing include, read at namespace scope where the name is used as a type - add <unordered_map> the same way.
  • The first diagnostic is a #error from inside the library headers saying the file requires compiler and library support for the ISO C++ 2011 standard, the file already includes <unordered_map>, and the note under the title error says 'std::unordered_map' is only available from C++11 onwards: the language mode is older than C++11 - the compile line shows -std=c++98, -std=c++03 or an equivalent setting; compile at -std=c++11 or later instead of changing code. The not-a-member errors underneath it are the same shape's fallout, and this shape appears at both probed older modes with identical wording.
  • The error is still the title error even though the file includes some other header: in the sweep above, each of <string>, <iostream>, <vector>, <algorithm>, <array> and <utility> in place of <unordered_map> left the title error in place - among the headers probed, none declares this name by accident, so a neighboring include is not a state to reason about for this name; add <unordered_map> itself.
  • The error instead is about passing a const map as the this argument discarding qualifiers, in a call to operator[]: the type was found and the access form is wrong for a const map - operator[] is non-const because it can insert; read with .at(), which has a const overload.
  • The failure is a static assertion from inside the library headers, hash function must be invocable with an argument of key type, with a chain of deleted-function errors above it that starts at the map's constructor: the include and mode are right and the key type has no usable hash - provide a std::hash specialization for the key type, or pass a custom hash as the third template argument.

Checklist

  • The file includes <unordered_map> itself - not a neighboring header in its place; in the sweep above, each of the six probed headers left the title error in place, so none of them stands in for <unordered_map>.
  • The compile line, or the build system's language standard setting, is C++11 or later; a pre-C++11 mode makes the library headers stop with a #error requiring the ISO C++ 2011 standard, and the not-a-member errors follow it.
  • The first diagnostic is read, not just the title error: a #error about the 2011 standard at the top means the mode is too old, and the not-a-member error with the "did you forget to #include <unordered_map>" note under it means the include is missing; the title error by itself cannot tell the two shapes apart, because both produce it.
  • The first error is read before the cascade: the expected primary-expression and 'was not declared in this scope' errors disappear when the name error at the top is fixed.
  • Values on a const map are read with .at() - never operator[], which is non-const because it inserts a missing key; .at() also throws std::out_of_range for a missing key instead of inserting one.
  • Every custom key type has a hash: a std::hash specialization for the key type, or a custom hash passed as the map's third template argument - equality alone is not enough for an unordered map.
  • No printed result depends on iterating the map: unordered map elements are in no particular order, so look values up by key, or print size and count results, which do not depend on order.
  • The fixed program compiles at C++11, runs, and prints 36 85, size 2 and count ada 1, in order.
  • 'std::map' Is Not a Member of 'std' Fix - the same missing-name fault on the ordered map: the nearest neighbor to this guide, with the same one-header rule - std::map lives in <map> where std::unordered_map lives in <unordered_map> - and the same since-C++ pattern in reverse, because std::map predates C++11 where the unordered map arrived with it.
  • 'std::tuple' Is Not a Member of 'std' Fix - the same missing-name fault on the tuple type, with one contrast worth seeing side by side: in its sweep, each probed header half-rescued the name, changing the error to an incomplete type, where in the sweep above no probed header changed this name's error at all - and the same older-mode shape as here, where its header also stops with a #error from inside the library headers first.
  • 'std::set' Is Not a Member of 'std' Fix - the same missing-name fault on the ordered set type, the key-only counterpart in the ordered family, where this guide's container carries a mapped value for each key.

Sources

  • cppreference.com, std::unordered_map — the type at the center of the error: the class template unordered_map since C++11, defined in header <unordered_map>, an associative container of key-value pairs with unique keys, organized into buckets by the hash of the key with elements in no particular order - with its template signature giving Hash defaulted to std::hash<Key> and KeyEqual defaulted to std::equal_to<Key>, the defaults the no-hash neighboring error breaks, and its member list giving at, operator[], count and size - the operations the fix program uses.
  • cppreference.com, Standard library header (C++11) — what the header declares: the unordered_map and unordered_multimap class templates and their comparison and swap functions, all in namespace std and since C++11 - the declarations a file gets by including <unordered_map> itself; in the sweep above, no probed neighbor brought them in.
  • cppreference.com, std::unordered_map::at — the access the fix program uses: since C++11, returning a reference to the mapped value for a key with bounds checking, throwing std::out_of_range if no such element exists, and provided in a const overload as well as a non-const one - the const overload the const-map neighboring error should switch to.
  • cppreference.com, std::unordered_map::operator[] — the insertion access: since C++11, returning a reference to the value mapped to a key and inserting it if it does not already exist, with the page's note that operator[] is non-const because it inserts the key if it does not exist, and that if this behavior is undesirable or the container is const, at may be used - the rule the const-map neighboring error enforces.

Keep Exploring