• 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(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>
do_insert_rv_test()27 void do_insert_rv_test()
28 {
29     typedef std::multimap<int, MoveOnly> M;
30     typedef typename M::iterator R;
31     typedef typename M::value_type VT;
32     M m;
33     R r = m.insert(VT(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(VT(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(VT(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(VT(3, 3));
52     assert(r == prev(m.end()));
53     assert(m.size() == 4);
54     assert(r->first == 3);
55     assert(r->second == 3);
56 }
57 
main()58 int main()
59 {
60     do_insert_rv_test<std::multimap<int, MoveOnly>>();
61     {
62         typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M;
63         do_insert_rv_test<M>();
64     }
65     {
66         typedef std::multimap<int, MoveOnly> M;
67         typedef M::iterator R;
68         M m;
69         R r = m.insert({2, MoveOnly(2)});
70         assert(r == m.begin());
71         assert(m.size() == 1);
72         assert(r->first == 2);
73         assert(r->second == 2);
74 
75         r = m.insert({1, MoveOnly(1)});
76         assert(r == m.begin());
77         assert(m.size() == 2);
78         assert(r->first == 1);
79         assert(r->second == 1);
80 
81         r = m.insert({3, MoveOnly(3)});
82         assert(r == prev(m.end()));
83         assert(m.size() == 3);
84         assert(r->first == 3);
85         assert(r->second == 3);
86 
87         r = m.insert({3, MoveOnly(3)});
88         assert(r == prev(m.end()));
89         assert(m.size() == 4);
90         assert(r->first == 3);
91         assert(r->second == 3);
92     }
93 }
94