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