Home | History | Annotate | Download | only in unord.multiset
      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 p)
     17 
     18 #include <unordered_set>
     19 #include <cassert>
     20 
     21 #include "min_allocator.h"
     22 
     23 struct TemplateConstructor
     24 {
     25     template<typename T>
     26     TemplateConstructor (const T&) {}
     27 };
     28 
     29 bool operator==(const TemplateConstructor&, const TemplateConstructor&) { return false; }
     30 struct Hash { size_t operator() (const TemplateConstructor &) const { return 0; } };
     31 
     32 int main()
     33 {
     34     {
     35         typedef std::unordered_multiset<int> C;
     36         typedef int P;
     37         P a[] =
     38         {
     39             P(1),
     40             P(2),
     41             P(3),
     42             P(4),
     43             P(1),
     44             P(2)
     45         };
     46         C c(a, a + sizeof(a)/sizeof(a[0]));
     47         C::const_iterator i = c.find(2);
     48         C::iterator j = c.erase(i);
     49         assert(c.size() == 5);
     50         assert(c.count(1) == 2);
     51         assert(c.count(2) == 1);
     52         assert(c.count(3) == 1);
     53         assert(c.count(4) == 1);
     54     }
     55 #if __cplusplus >= 201103L
     56     {
     57         typedef std::unordered_multiset<int, std::hash<int>,
     58                                       std::equal_to<int>, min_allocator<int>> C;
     59         typedef int P;
     60         P a[] =
     61         {
     62             P(1),
     63             P(2),
     64             P(3),
     65             P(4),
     66             P(1),
     67             P(2)
     68         };
     69         C c(a, a + sizeof(a)/sizeof(a[0]));
     70         C::const_iterator i = c.find(2);
     71         C::iterator j = c.erase(i);
     72         assert(c.size() == 5);
     73         assert(c.count(1) == 2);
     74         assert(c.count(2) == 1);
     75         assert(c.count(3) == 1);
     76         assert(c.count(4) == 1);
     77     }
     78 #endif
     79 #if __cplusplus >= 201402L
     80     {
     81     //  This is LWG #2059
     82         typedef TemplateConstructor T;
     83         typedef std::unordered_set<T, 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