• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 multimap
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_rv_test()27 void do_insert_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.cend(), 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.cend(), 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.cend(), 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.cend(), P(3, 2));
52     assert(r == prev(m.end()));
53     assert(m.size() == 4);
54     assert(r->first == 3);
55     assert(r->second == 2);
56 }
57 
main()58 int main()
59 {
60     do_insert_rv_test<std::multimap<int, MoveOnly>, std::pair<int, MoveOnly> >();
61     do_insert_rv_test<std::multimap<int, MoveOnly>, std::pair<const int, MoveOnly> >();
62 
63     {
64         typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
65         typedef std::pair<int, MoveOnly> P;
66         typedef std::pair<const int, MoveOnly> CP;
67         do_insert_rv_test<M, P>();
68         do_insert_rv_test<M, CP>();
69 
70     }
71     {
72         typedef std::multimap<int, MoveOnly> M;
73         typedef M::iterator R;
74         M m;
75         R r = m.insert(m.cend(), {2, MoveOnly(2)});
76         assert(r == m.begin());
77         assert(m.size() == 1);
78         assert(r->first == 2);
79         assert(r->second == 2);
80 
81         r = m.insert(m.cend(), {1, MoveOnly(1)});
82         assert(r == m.begin());
83         assert(m.size() == 2);
84         assert(r->first == 1);
85         assert(r->second == 1);
86 
87         r = m.insert(m.cend(), {3, MoveOnly(3)});
88         assert(r == prev(m.end()));
89         assert(m.size() == 3);
90         assert(r->first == 3);
91         assert(r->second == 3);
92 
93         r = m.insert(m.cend(), {3, MoveOnly(2)});
94         assert(r == prev(m.end()));
95         assert(m.size() == 4);
96         assert(r->first == 3);
97         assert(r->second == 2);
98     }
99 }
100