]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / unord / unord.multiset / unord.multiset.cnstr / range.pass.cpp
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 // template <class InputIterator>
17 //     unordered_multiset(InputIterator first, InputIterator last);
18
19 #include <unordered_set>
20 #include <cassert>
21 #include <cfloat>
22 #include <cstddef>
23
24 #include "test_macros.h"
25 #include "test_iterators.h"
26 #include "../../../test_compare.h"
27 #include "../../../test_hash.h"
28 #include "test_allocator.h"
29 #include "min_allocator.h"
30
31 int main()
32 {
33     {
34         typedef std::unordered_multiset<int,
35                                    test_hash<std::hash<int> >,
36                                    test_compare<std::equal_to<int> >,
37                                    test_allocator<int>
38                                    > C;
39         typedef int P;
40         P a[] =
41         {
42             P(1),
43             P(2),
44             P(3),
45             P(4),
46             P(1),
47             P(2)
48         };
49         C c(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])));
50         assert(c.bucket_count() >= 7);
51         assert(c.size() == 6);
52         assert(c.count(1) == 2);
53         assert(c.count(2) == 2);
54         assert(c.count(3) == 1);
55         assert(c.count(4) == 1);
56         assert(c.hash_function() == test_hash<std::hash<int> >());
57         assert(c.key_eq() == test_compare<std::equal_to<int> >());
58         assert(c.get_allocator() == test_allocator<int>());
59         assert(!c.empty());
60         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
61         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
62         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
63         assert(c.max_load_factor() == 1);
64     }
65 #if TEST_STD_VER >= 11
66     {
67         typedef std::unordered_multiset<int,
68                                    test_hash<std::hash<int> >,
69                                    test_compare<std::equal_to<int> >,
70                                    min_allocator<int>
71                                    > 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(input_iterator<P*>(a), input_iterator<P*>(a + sizeof(a)/sizeof(a[0])));
83         assert(c.bucket_count() >= 7);
84         assert(c.size() == 6);
85         assert(c.count(1) == 2);
86         assert(c.count(2) == 2);
87         assert(c.count(3) == 1);
88         assert(c.count(4) == 1);
89         assert(c.hash_function() == test_hash<std::hash<int> >());
90         assert(c.key_eq() == test_compare<std::equal_to<int> >());
91         assert(c.get_allocator() == min_allocator<int>());
92         assert(!c.empty());
93         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
94         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
95         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
96         assert(c.max_load_factor() == 1);
97     }
98 #if TEST_STD_VER > 11
99     {
100         typedef int T;
101         typedef test_hash<std::hash<T>> HF;
102         typedef test_compare<std::equal_to<T>> Comp;
103         typedef test_allocator<T> A;
104         typedef std::unordered_multiset<T, HF, Comp, A> C;
105         T arr[] =
106         {
107             T(1),
108             T(2),
109             T(3),
110             T(4),
111             T(1),
112             T(2)
113         };
114         A a(42);
115         C c(input_iterator<T*>(arr), input_iterator<T*>(arr + sizeof(arr)/sizeof(arr[0])), 12, a);
116         assert(c.bucket_count() >= 12);
117         assert(c.size() == 6);
118         assert(c.count(1) == 2);
119         assert(c.count(2) == 2);
120         assert(c.count(3) == 1);
121         assert(c.count(4) == 1);
122         assert(c.hash_function() == HF());
123         assert(c.key_eq() == Comp());
124         assert(c.get_allocator() == a);
125         assert(!(c.get_allocator() == A()));
126         assert(!c.empty());
127         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
128         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
129         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
130         assert(c.max_load_factor() == 1);
131     }
132     {
133         typedef int T;
134         typedef test_hash<std::hash<T>> HF;
135         typedef test_compare<std::equal_to<T>> Comp;
136         typedef test_allocator<T> A;
137         typedef std::unordered_multiset<T, HF, Comp, A> C;
138         T arr[] =
139         {
140             T(1),
141             T(2),
142             T(3),
143             T(4),
144             T(1),
145             T(2)
146         };
147         HF hf(43);
148         A a(42);
149         C c(input_iterator<T*>(arr), input_iterator<T*>(arr + sizeof(arr)/sizeof(arr[0])), 16, hf, a);
150         assert(c.bucket_count() >= 16);
151         assert(c.size() == 6);
152         assert(c.count(1) == 2);
153         assert(c.count(2) == 2);
154         assert(c.count(3) == 1);
155         assert(c.count(4) == 1);
156         assert(c.hash_function() == hf);
157         assert(!(c.hash_function() == HF()));
158         assert(c.key_eq() == Comp());
159         assert(c.get_allocator() == a);
160         assert(!(c.get_allocator() == A()));
161         assert(!c.empty());
162         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
163         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
164         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
165         assert(c.max_load_factor() == 1);
166     }
167 #endif
168 #endif
169 }