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