deduct.pass.cpp
5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <set>
// UNSUPPORTED: c++98, c++03, c++11, c++14
// UNSUPPORTED: libcpp-no-deduction-guides
// UNSUPPORTED: apple-clang-9.1
// template<class InputIterator,
// class Compare = less<iter-value-type<InputIterator>>,
// class Allocator = allocator<iter-value-type<InputIterator>>>
// set(InputIterator, InputIterator,
// Compare = Compare(), Allocator = Allocator())
// -> set<iter-value-type<InputIterator>, Compare, Allocator>;
// template<class Key, class Compare = less<Key>,
// class Allocator = allocator<Key>>
// set(initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
// -> set<Key, Compare, Allocator>;
// template<class InputIterator, class Allocator>
// set(InputIterator, InputIterator, Allocator)
// -> set<iter-value-type<InputIterator>,
// less<iter-value-type<InputIterator>>, Allocator>;
// template<class Key, class Allocator>
// set(initializer_list<Key>, Allocator)
// -> set<Key, less<Key>, Allocator>;
#include <algorithm> // std::equal
#include <cassert>
#include <climits> // INT_MAX
#include <functional>
#include <set>
#include <type_traits>
#include "test_allocator.h"
struct NotAnAllocator {
friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }
};
int main(int, char **) {
{
const int arr[] = { 1, 2, 1, INT_MAX, 3 };
std::set s(std::begin(arr), std::end(arr));
ASSERT_SAME_TYPE(decltype(s), std::set<int>);
const int expected_s[] = { 1, 2, 3, INT_MAX };
assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
std::end(expected_s)));
}
{
const int arr[] = { 1, 2, 1, INT_MAX, 3 };
std::set s(std::begin(arr), std::end(arr), std::greater<int>());
ASSERT_SAME_TYPE(decltype(s), std::set<int, std::greater<int> >);
const int expected_s[] = { INT_MAX, 3, 2, 1 };
assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
std::end(expected_s)));
}
{
const int arr[] = { 1, 2, 1, INT_MAX, 3 };
std::set s(std::begin(arr), std::end(arr), std::greater<int>(),
test_allocator<int>(0, 42));
ASSERT_SAME_TYPE(decltype(s),
std::set<int, std::greater<int>, test_allocator<int> >);
const int expected_s[] = { INT_MAX, 3, 2, 1 };
assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
std::end(expected_s)));
assert(s.get_allocator().get_id() == 42);
}
{
std::set<long> source;
std::set s(source);
ASSERT_SAME_TYPE(decltype(s), std::set<long>);
assert(s.size() == 0);
}
{
std::set<long> source;
std::set s{ source }; // braces instead of parens
ASSERT_SAME_TYPE(decltype(s), std::set<long>);
assert(s.size() == 0);
}
{
std::set<long> source;
std::set s(source, std::set<long>::allocator_type());
ASSERT_SAME_TYPE(decltype(s), std::set<long>);
assert(s.size() == 0);
}
{
std::set s{ 1, 2, 1, INT_MAX, 3 };
ASSERT_SAME_TYPE(decltype(s), std::set<int>);
const int expected_s[] = { 1, 2, 3, INT_MAX };
assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
std::end(expected_s)));
}
{
std::set s({ 1, 2, 1, INT_MAX, 3 }, std::greater<int>());
ASSERT_SAME_TYPE(decltype(s), std::set<int, std::greater<int> >);
const int expected_s[] = { INT_MAX, 3, 2, 1 };
assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
std::end(expected_s)));
}
{
std::set s({ 1, 2, 1, INT_MAX, 3 }, std::greater<int>(),
test_allocator<int>(0, 43));
ASSERT_SAME_TYPE(decltype(s),
std::set<int, std::greater<int>, test_allocator<int> >);
const int expected_s[] = { INT_MAX, 3, 2, 1 };
assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
std::end(expected_s)));
assert(s.get_allocator().get_id() == 43);
}
{
const int arr[] = { 1, 2, 1, INT_MAX, 3 };
std::set s(std::begin(arr), std::end(arr), test_allocator<int>(0, 44));
ASSERT_SAME_TYPE(decltype(s),
std::set<int, std::less<int>, test_allocator<int> >);
const int expected_s[] = { 1, 2, 3, INT_MAX };
assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
std::end(expected_s)));
assert(s.get_allocator().get_id() == 44);
}
{
std::set s({ 1, 2, 1, INT_MAX, 3 }, test_allocator<int>(0, 45));
ASSERT_SAME_TYPE(decltype(s),
std::set<int, std::less<int>, test_allocator<int> >);
const int expected_s[] = { 1, 2, 3, INT_MAX };
assert(std::equal(s.begin(), s.end(), std::begin(expected_s),
std::end(expected_s)));
assert(s.get_allocator().get_id() == 45);
}
{
NotAnAllocator a;
std::set s{ a }; // set(initializer_list<NotAnAllocator>)
ASSERT_SAME_TYPE(decltype(s), std::set<NotAnAllocator>);
assert(s.size() == 1);
}
{
std::set<long> source;
std::set s{ source, source }; // set(initializer_list<set<long>>)
ASSERT_SAME_TYPE(decltype(s), std::set<std::set<long> >);
assert(s.size() == 1);
}
{
NotAnAllocator a;
std::set s{ a, a }; // set(initializer_list<NotAnAllocator>)
ASSERT_SAME_TYPE(decltype(s), std::set<NotAnAllocator>);
assert(s.size() == 1);
}
{
int source[3] = { 3, 4, 5 };
std::set s(source, source + 3); // set(InputIterator, InputIterator)
ASSERT_SAME_TYPE(decltype(s), std::set<int>);
assert(s.size() == 3);
}
{
int source[3] = { 3, 4, 5 };
std::set s{ source, source + 3 }; // set(initializer_list<int*>)
ASSERT_SAME_TYPE(decltype(s), std::set<int *>);
assert(s.size() == 2);
}
return 0;
}