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