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