1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03 |
10 | |
11 | // <map> |
12 | |
13 | // class multimap |
14 | |
15 | // template <class P> |
16 | // iterator insert(const_iterator position, P&& p); |
17 | |
18 | #include <map> |
19 | #include <cassert> |
20 | |
21 | #include "MoveOnly.h" |
22 | #include "min_allocator.h" |
23 | #include "test_macros.h" |
24 | |
25 | template <class Container, class Pair> |
26 | void do_insert_rv_test() |
27 | { |
28 | typedef Container M; |
29 | typedef Pair P; |
30 | typedef typename M::iterator R; |
31 | M m; |
32 | R r = m.insert(m.cend(), P(2, 2)); |
33 | assert(r == m.begin()); |
34 | assert(m.size() == 1); |
35 | assert(r->first == 2); |
36 | assert(r->second == 2); |
37 | |
38 | r = m.insert(m.cend(), P(1, 1)); |
39 | assert(r == m.begin()); |
40 | assert(m.size() == 2); |
41 | assert(r->first == 1); |
42 | assert(r->second == 1); |
43 | |
44 | r = m.insert(m.cend(), P(3, 3)); |
45 | assert(r == std::prev(m.end())); |
46 | assert(m.size() == 3); |
47 | assert(r->first == 3); |
48 | assert(r->second == 3); |
49 | |
50 | r = m.insert(m.cend(), P(3, 2)); |
51 | assert(r == std::prev(m.end())); |
52 | assert(m.size() == 4); |
53 | assert(r->first == 3); |
54 | assert(r->second == 2); |
55 | } |
56 | |
57 | int main(int, char**) |
58 | { |
59 | do_insert_rv_test<std::multimap<int, MoveOnly>, std::pair<int, MoveOnly> >(); |
60 | do_insert_rv_test<std::multimap<int, MoveOnly>, std::pair<const int, MoveOnly> >(); |
61 | |
62 | { |
63 | typedef std::multimap<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_rv_test<M, P>(); |
67 | do_insert_rv_test<M, CP>(); |
68 | |
69 | } |
70 | { |
71 | typedef std::multimap<int, MoveOnly> M; |
72 | typedef M::iterator R; |
73 | M m; |
74 | R r = m.insert(m.cend(), {2, MoveOnly(2)}); |
75 | assert(r == m.begin()); |
76 | assert(m.size() == 1); |
77 | assert(r->first == 2); |
78 | assert(r->second == 2); |
79 | |
80 | r = m.insert(m.cend(), {1, MoveOnly(1)}); |
81 | assert(r == m.begin()); |
82 | assert(m.size() == 2); |
83 | assert(r->first == 1); |
84 | assert(r->second == 1); |
85 | |
86 | r = m.insert(m.cend(), {3, MoveOnly(3)}); |
87 | assert(r == std::prev(m.end())); |
88 | assert(m.size() == 3); |
89 | assert(r->first == 3); |
90 | assert(r->second == 3); |
91 | |
92 | r = m.insert(m.cend(), {3, MoveOnly(2)}); |
93 | assert(r == std::prev(m.end())); |
94 | assert(m.size() == 4); |
95 | assert(r->first == 3); |
96 | assert(r->second == 2); |
97 | } |
98 | |
99 | return 0; |
100 | } |
101 | |