equal_range_non_const.pass.cpp (3187B)
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_multimap 15 16 // pair<iterator, iterator> equal_range(const key_type& k); 17 18 #include <unordered_map> 19 #include <string> 20 #include <set> 21 #include <cassert> 22 23 #include "min_allocator.h" 24 25 int main() 26 { 27 { 28 typedef std::unordered_multimap<int, std::string> C; 29 typedef C::iterator I; 30 typedef std::pair<int, std::string> P; 31 P a[] = 32 { 33 P(10, "ten"), 34 P(20, "twenty"), 35 P(30, "thirty"), 36 P(40, "forty"), 37 P(50, "fifty"), 38 P(50, "fiftyA"), 39 P(50, "fiftyB"), 40 P(60, "sixty"), 41 P(70, "seventy"), 42 P(80, "eighty"), 43 }; 44 C c(std::begin(a), std::end(a)); 45 std::pair<I, I> r = c.equal_range(30); 46 assert(std::distance(r.first, r.second) == 1); 47 assert(r.first->first == 30); 48 assert(r.first->second == "thirty"); 49 r = c.equal_range(5); 50 assert(std::distance(r.first, r.second) == 0); 51 r = c.equal_range(50); 52 std::set<std::string> s; 53 s.insert("fifty"); 54 s.insert("fiftyA"); 55 s.insert("fiftyB"); 56 for ( int i = 0; i < 3; ++i ) 57 { 58 assert(r.first->first == 50); 59 assert(s.find(r.first->second) != s.end()); 60 s.erase(s.find(r.first->second)); 61 ++r.first; 62 } 63 } 64 #if TEST_STD_VER >= 11 65 { 66 typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>, 67 min_allocator<std::pair<const int, std::string>>> C; 68 typedef C::iterator I; 69 typedef std::pair<int, std::string> P; 70 P a[] = 71 { 72 P(10, "ten"), 73 P(20, "twenty"), 74 P(30, "thirty"), 75 P(40, "forty"), 76 P(50, "fifty"), 77 P(50, "fiftyA"), 78 P(50, "fiftyB"), 79 P(60, "sixty"), 80 P(70, "seventy"), 81 P(80, "eighty"), 82 }; 83 C c(std::begin(a), std::end(a)); 84 std::pair<I, I> r = c.equal_range(30); 85 assert(std::distance(r.first, r.second) == 1); 86 assert(r.first->first == 30); 87 assert(r.first->second == "thirty"); 88 r = c.equal_range(5); 89 assert(std::distance(r.first, r.second) == 0); 90 r = c.equal_range(50); 91 std::set<std::string> s; 92 s.insert("fifty"); 93 s.insert("fiftyA"); 94 s.insert("fiftyB"); 95 for ( int i = 0; i < 3; ++i ) 96 { 97 assert(r.first->first == 50); 98 assert(s.find(r.first->second) != s.end()); 99 s.erase(s.find(r.first->second)); 100 ++r.first; 101 } 102 } 103 #endif 104 }