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 // iterator emplace_hint(const_iterator position, 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 M::iterator R;
30 M m;
31 assert(DefaultOnly::count == 0);
32 R r = m.emplace_hint(m.cend());
33 assert(r == m.begin());
34 assert(m.size() == 1);
35 assert(*m.begin() == DefaultOnly());
36 assert(DefaultOnly::count == 1);
37
38 r = m.emplace_hint(m.cbegin());
39 assert(r == m.begin());
40 assert(m.size() == 1);
41 assert(*m.begin() == DefaultOnly());
42 assert(DefaultOnly::count == 1);
43 }
44 assert(DefaultOnly::count == 0);
45 {
46 typedef std::set<Emplaceable> M;
47 typedef M::iterator R;
48 M m;
49 R r = m.emplace_hint(m.cend());
50 assert(r == m.begin());
51 assert(m.size() == 1);
52 assert(*m.begin() == Emplaceable());
53 r = m.emplace_hint(m.cend(), 2, 3.5);
54 assert(r == next(m.begin()));
55 assert(m.size() == 2);
56 assert(*r == Emplaceable(2, 3.5));
57 r = m.emplace_hint(m.cbegin(), 2, 3.5);
58 assert(r == next(m.begin()));
59 assert(m.size() == 2);
60 assert(*r == Emplaceable(2, 3.5));
61 }
62 {
63 typedef std::set<int> M;
64 typedef M::iterator R;
65 M m;
66 R r = m.emplace_hint(m.cend(), M::value_type(2));
67 assert(r == m.begin());
68 assert(m.size() == 1);
69 assert(*r == 2);
70 }
71 #if __cplusplus >= 201103L
72 {
73 typedef std::set<int, std::less<int>, min_allocator<int>> M;
74 typedef M::iterator R;
75 M m;
76 R r = m.emplace_hint(m.cend(), M::value_type(2));
77 assert(r == m.begin());
78 assert(m.size() == 1);
79 assert(*r == 2);
80 }
81 #endif
82 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
83 }
84