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