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 // <set>
11
12 // class set
13
14 // template <class... Args>
15 // pair<iterator, bool> emplace(Args&&... args);
16
17 #include <set>
18 #include <cassert>
19
20 #include "../../Emplaceable.h"
21 #include "DefaultOnly.h"
22 #include "min_allocator.h"
23
main()24 int main()
25 {
26 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
27 {
28 typedef std::set<DefaultOnly> M;
29 typedef std::pair<M::iterator, bool> R;
30 M m;
31 assert(DefaultOnly::count == 0);
32 R r = m.emplace();
33 assert(r.second);
34 assert(r.first == m.begin());
35 assert(m.size() == 1);
36 assert(*m.begin() == DefaultOnly());
37 assert(DefaultOnly::count == 1);
38
39 r = m.emplace();
40 assert(!r.second);
41 assert(r.first == m.begin());
42 assert(m.size() == 1);
43 assert(*m.begin() == DefaultOnly());
44 assert(DefaultOnly::count == 1);
45 }
46 assert(DefaultOnly::count == 0);
47 {
48 typedef std::set<Emplaceable> M;
49 typedef std::pair<M::iterator, bool> R;
50 M m;
51 R r = m.emplace();
52 assert(r.second);
53 assert(r.first == m.begin());
54 assert(m.size() == 1);
55 assert(*m.begin() == Emplaceable());
56 r = m.emplace(2, 3.5);
57 assert(r.second);
58 assert(r.first == next(m.begin()));
59 assert(m.size() == 2);
60 assert(*r.first == Emplaceable(2, 3.5));
61 r = m.emplace(2, 3.5);
62 assert(!r.second);
63 assert(r.first == next(m.begin()));
64 assert(m.size() == 2);
65 assert(*r.first == Emplaceable(2, 3.5));
66 }
67 {
68 typedef std::set<int> M;
69 typedef std::pair<M::iterator, bool> R;
70 M m;
71 R r = m.emplace(M::value_type(2));
72 assert(r.second);
73 assert(r.first == m.begin());
74 assert(m.size() == 1);
75 assert(*r.first == 2);
76 }
77 #if TEST_STD_VER >= 11
78 {
79 typedef std::set<int, std::less<int>, min_allocator<int>> M;
80 typedef std::pair<M::iterator, bool> R;
81 M m;
82 R r = m.emplace(M::value_type(2));
83 assert(r.second);
84 assert(r.first == m.begin());
85 assert(m.size() == 1);
86 assert(*r.first == 2);
87 }
88 #endif
89 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
90 }
91