blob: 3e0207480146cad80f12a1630b93757081e59438 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. 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_set
15
16// unordered_set(unordered_set&& u, const allocator_type& a);
17
18#include <unordered_set>
19#include <cassert>
20
21#include "../../../test_compare.h"
22#include "../../../test_hash.h"
23#include "../../../test_allocator.h"
24
25int main()
26{
Howard Hinnant73d21a42010-09-04 23:28:19 +000027#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000028 {
29 typedef int P;
30 typedef test_allocator<int> A;
31 typedef std::unordered_set<int,
32 test_hash<std::hash<int> >,
33 test_compare<std::equal_to<int> >,
34 A
35 > C;
36 P a[] =
37 {
38 P(1),
39 P(2),
40 P(3),
41 P(4),
42 P(1),
43 P(2)
44 };
45 C c0(a, a + sizeof(a)/sizeof(a[0]),
46 7,
47 test_hash<std::hash<int> >(8),
48 test_compare<std::equal_to<int> >(9),
49 A(10)
50 );
51 C c(std::move(c0), A(12));
52 assert(c.bucket_count() >= 5);
53 assert(c.size() == 4);
54 assert(c.count(1) == 1);
55 assert(c.count(2) == 1);
56 assert(c.count(3) == 1);
57 assert(c.count(4) == 1);
58 assert(c.hash_function() == test_hash<std::hash<int> >(8));
59 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
60 assert(c.get_allocator() == A(12));
61 assert(!c.empty());
62 assert(std::distance(c.begin(), c.end()) == c.size());
63 assert(std::distance(c.cbegin(), c.cend()) == c.size());
64 assert(c.load_factor() == (float)c.size()/c.bucket_count());
65 assert(c.max_load_factor() == 1);
66
67 assert(c0.empty());
68 }
69 {
70 typedef int P;
71 typedef test_allocator<int> A;
72 typedef std::unordered_set<int,
73 test_hash<std::hash<int> >,
74 test_compare<std::equal_to<int> >,
75 A
76 > C;
77 P a[] =
78 {
79 P(1),
80 P(2),
81 P(3),
82 P(4),
83 P(1),
84 P(2)
85 };
86 C c0(a, a + sizeof(a)/sizeof(a[0]),
87 7,
88 test_hash<std::hash<int> >(8),
89 test_compare<std::equal_to<int> >(9),
90 A(10)
91 );
92 C c(std::move(c0), A(10));
93 assert(c.bucket_count() >= 5);
94 assert(c.size() == 4);
95 assert(c.count(1) == 1);
96 assert(c.count(2) == 1);
97 assert(c.count(3) == 1);
98 assert(c.count(4) == 1);
99 assert(c.hash_function() == test_hash<std::hash<int> >(8));
100 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
101 assert(c.get_allocator() == A(10));
102 assert(!c.empty());
103 assert(std::distance(c.begin(), c.end()) == c.size());
104 assert(std::distance(c.cbegin(), c.cend()) == c.size());
105 assert(c.load_factor() == (float)c.size()/c.bucket_count());
106 assert(c.max_load_factor() == 1);
107
108 assert(c0.empty());
109 }
Howard Hinnant73d21a42010-09-04 23:28:19 +0000110#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000111}