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_set> 11 12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, 13 // class Alloc = allocator<Value>> 14 // class unordered_multiset 15 16 // iterator erase(const_iterator first, const_iterator last) 17 18 #include <unordered_set> 19 #include <cassert> 20 #include <iterator> 21 22 #include "min_allocator.h" 23 24 int main() 25 { 26 { 27 typedef std::unordered_multiset<int> C; 28 typedef int P; 29 P a[] = 30 { 31 P(1), 32 P(2), 33 P(3), 34 P(4), 35 P(1), 36 P(2) 37 }; 38 C c(a, a + sizeof(a)/sizeof(a[0])); 39 C::const_iterator i = c.find(2); 40 C::const_iterator j = next(i, 2); 41 C::iterator k = c.erase(i, i); 42 assert(k == i); 43 assert(c.size() == 6); 44 assert(c.count(1) == 2); 45 assert(c.count(2) == 2); 46 assert(c.count(3) == 1); 47 assert(c.count(4) == 1); 48 49 k = c.erase(i, j); 50 assert(c.size() == 4); 51 assert(c.count(1) == 2); 52 assert(c.count(3) == 1); 53 assert(c.count(4) == 1); 54 55 k = c.erase(c.cbegin(), c.cend()); 56 assert(c.size() == 0); 57 assert(k == c.end()); 58 } 59 #if TEST_STD_VER >= 11 60 { 61 typedef std::unordered_multiset<int, std::hash<int>, 62 std::equal_to<int>, min_allocator<int>> C; 63 typedef int P; 64 P a[] = 65 { 66 P(1), 67 P(2), 68 P(3), 69 P(4), 70 P(1), 71 P(2) 72 }; 73 C c(a, a + sizeof(a)/sizeof(a[0])); 74 C::const_iterator i = c.find(2); 75 C::const_iterator j = next(i, 2); 76 C::iterator k = c.erase(i, i); 77 assert(k == i); 78 assert(c.size() == 6); 79 assert(c.count(1) == 2); 80 assert(c.count(2) == 2); 81 assert(c.count(3) == 1); 82 assert(c.count(4) == 1); 83 84 k = c.erase(i, j); 85 assert(c.size() == 4); 86 assert(c.count(1) == 2); 87 assert(c.count(3) == 1); 88 assert(c.count(4) == 1); 89 90 k = c.erase(c.cbegin(), c.cend()); 91 assert(c.size() == 0); 92 assert(k == c.end()); 93 } 94 #endif 95 } 96