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       begin();
17 // iterator       end();
18 // const_iterator begin()  const;
19 // const_iterator end()    const;
20 // const_iterator cbegin() const;
21 // const_iterator cend()   const;
22 
23 #include <unordered_set>
24 #include <cassert>
25 
26 #include "min_allocator.h"
27 
main()28 int main()
29 {
30     {
31         typedef std::unordered_multiset<int> C;
32         typedef int P;
33         P a[] =
34         {
35             P(1),
36             P(2),
37             P(3),
38             P(4),
39             P(1),
40             P(2)
41         };
42         C c(a, a + sizeof(a)/sizeof(a[0]));
43         assert(c.bucket_count() >= 7);
44         assert(c.size() == 6);
45         assert(std::distance(c.begin(), c.end()) == c.size());
46         assert(std::distance(c.cbegin(), c.cend()) == c.size());
47         C::iterator i;
48     }
49     {
50         typedef std::unordered_multiset<int> C;
51         typedef int P;
52         P a[] =
53         {
54             P(1),
55             P(2),
56             P(3),
57             P(4),
58             P(1),
59             P(2)
60         };
61         const C c(a, a + sizeof(a)/sizeof(a[0]));
62         assert(c.bucket_count() >= 7);
63         assert(c.size() == 6);
64         assert(std::distance(c.begin(), c.end()) == c.size());
65         assert(std::distance(c.cbegin(), c.cend()) == c.size());
66         C::const_iterator i;
67     }
68 #if __cplusplus >= 201103L
69     {
70         typedef std::unordered_multiset<int, std::hash<int>,
71                                       std::equal_to<int>, min_allocator<int>> C;
72         typedef int P;
73         P a[] =
74         {
75             P(1),
76             P(2),
77             P(3),
78             P(4),
79             P(1),
80             P(2)
81         };
82         C c(a, a + sizeof(a)/sizeof(a[0]));
83         assert(c.bucket_count() >= 7);
84         assert(c.size() == 6);
85         assert(std::distance(c.begin(), c.end()) == c.size());
86         assert(std::distance(c.cbegin(), c.cend()) == c.size());
87         C::iterator i;
88     }
89     {
90         typedef std::unordered_multiset<int, std::hash<int>,
91                                       std::equal_to<int>, min_allocator<int>> C;
92         typedef int P;
93         P a[] =
94         {
95             P(1),
96             P(2),
97             P(3),
98             P(4),
99             P(1),
100             P(2)
101         };
102         const C c(a, a + sizeof(a)/sizeof(a[0]));
103         assert(c.bucket_count() >= 7);
104         assert(c.size() == 6);
105         assert(std::distance(c.begin(), c.end()) == c.size());
106         assert(std::distance(c.cbegin(), c.cend()) == c.size());
107         C::const_iterator i;
108     }
109 #endif
110 #if _LIBCPP_STD_VER > 11
111     { // N3644 testing
112         typedef std::unordered_multiset<int> C;
113         C::iterator ii1{}, ii2{};
114         C::iterator ii4 = ii1;
115         C::const_iterator cii{};
116         assert ( ii1 == ii2 );
117         assert ( ii1 == ii4 );
118 
119         assert (!(ii1 != ii2 ));
120 
121         assert ( (ii1 == cii ));
122         assert ( (cii == ii1 ));
123         assert (!(ii1 != cii ));
124         assert (!(cii != ii1 ));
125     }
126 #endif
127 }
128