1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03 |
10 | |
11 | // <unordered_set> |
12 | |
13 | // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
14 | // class Alloc = allocator<Value>> |
15 | // class unordered_set |
16 | |
17 | // template <class... Args> |
18 | // pair<iterator, bool> emplace(Args&&... args); |
19 | |
20 | #include <unordered_set> |
21 | #include <cassert> |
22 | |
23 | #include "test_macros.h" |
24 | #include "../../Emplaceable.h" |
25 | #include "min_allocator.h" |
26 | |
27 | int main(int, char**) |
28 | { |
29 | { |
30 | typedef std::unordered_set<Emplaceable> C; |
31 | typedef std::pair<C::iterator, bool> R; |
32 | C c; |
33 | R r = c.emplace(); |
34 | assert(c.size() == 1); |
35 | assert(*r.first == Emplaceable()); |
36 | assert(r.second); |
37 | |
38 | r = c.emplace(Emplaceable(5, 6)); |
39 | assert(c.size() == 2); |
40 | assert(*r.first == Emplaceable(5, 6)); |
41 | assert(r.second); |
42 | |
43 | r = c.emplace(5, 6); |
44 | assert(c.size() == 2); |
45 | assert(*r.first == Emplaceable(5, 6)); |
46 | assert(!r.second); |
47 | } |
48 | { |
49 | typedef std::unordered_set<Emplaceable, std::hash<Emplaceable>, |
50 | std::equal_to<Emplaceable>, min_allocator<Emplaceable>> C; |
51 | typedef std::pair<C::iterator, bool> R; |
52 | C c; |
53 | R r = c.emplace(); |
54 | assert(c.size() == 1); |
55 | assert(*r.first == Emplaceable()); |
56 | assert(r.second); |
57 | |
58 | r = c.emplace(Emplaceable(5, 6)); |
59 | assert(c.size() == 2); |
60 | assert(*r.first == Emplaceable(5, 6)); |
61 | assert(r.second); |
62 | |
63 | r = c.emplace(5, 6); |
64 | assert(c.size() == 2); |
65 | assert(*r.first == Emplaceable(5, 6)); |
66 | assert(!r.second); |
67 | } |
68 | |
69 | return 0; |
70 | } |
71 | |