1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <unordered_map> 11 12 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, 13 // class Alloc = allocator<pair<const Key, T>>> 14 // class unordered_map 15 16 // iterator erase(const_iterator p) 17 18 #include <unordered_map> 19 #include <string> 20 #include <cassert> 21 22 #include "test_macros.h" 23 #include "min_allocator.h" 24 25 struct TemplateConstructor 26 { 27 template<typename T> 28 TemplateConstructor (const T&) {} 29 }; 30 31 bool operator==(const TemplateConstructor&, const TemplateConstructor&) { return false; } 32 struct Hash { size_t operator() (const TemplateConstructor &) const { return 0; } }; 33 34 int main() 35 { 36 { 37 typedef std::unordered_map<int, std::string> C; 38 typedef std::pair<int, std::string> P; 39 P a[] = 40 { 41 P(1, "one"), 42 P(2, "two"), 43 P(3, "three"), 44 P(4, "four"), 45 P(1, "four"), 46 P(2, "four"), 47 }; 48 C c(a, a + sizeof(a)/sizeof(a[0])); 49 C::const_iterator i = c.find(2); 50 c.erase(i); 51 assert(c.size() == 3); 52 assert(c.at(1) == "one"); 53 assert(c.at(3) == "three"); 54 assert(c.at(4) == "four"); 55 } 56 #if TEST_STD_VER >= 11 57 { 58 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, 59 min_allocator<std::pair<const int, std::string>>> C; 60 typedef std::pair<int, std::string> P; 61 P a[] = 62 { 63 P(1, "one"), 64 P(2, "two"), 65 P(3, "three"), 66 P(4, "four"), 67 P(1, "four"), 68 P(2, "four"), 69 }; 70 C c(a, a + sizeof(a)/sizeof(a[0])); 71 C::const_iterator i = c.find(2); 72 c.erase(i); 73 assert(c.size() == 3); 74 assert(c.at(1) == "one"); 75 assert(c.at(3) == "three"); 76 assert(c.at(4) == "four"); 77 } 78 #endif 79 #if TEST_STD_VER >= 14 80 { 81 // This is LWG #2059 82 typedef TemplateConstructor T; 83 typedef std::unordered_map<T, int, Hash> C; 84 typedef C::iterator I; 85 86 C m; 87 T a{0}; 88 I it = m.find(a); 89 if (it != m.end()) 90 m.erase(it); 91 } 92 #endif 93 } 94