Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Eric Fiselier | 91a1565 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 10 | // UNSUPPORTED: c++98, c++03 |
| 11 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 12 | // <map> |
| 13 | |
| 14 | // class multimap |
| 15 | |
| 16 | // template <class P> |
| 17 | // iterator insert(P&& p); |
| 18 | |
| 19 | #include <map> |
| 20 | #include <cassert> |
| 21 | |
Marshall Clow | df00d5e | 2015-01-28 21:22:53 +0000 | [diff] [blame] | 22 | #include "MoveOnly.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 23 | #include "min_allocator.h" |
Marshall Clow | 7861de2 | 2016-01-05 19:53:31 +0000 | [diff] [blame] | 24 | #include "test_macros.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 25 | |
Eric Fiselier | 91a1565 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 26 | template <class Container> |
| 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 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 58 | int main() |
| 59 | { |
Eric Fiselier | 91a1565 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 60 | do_insert_rv_test<std::multimap<int, MoveOnly>>(); |
Howard Hinnant | 70342b9 | 2013-06-19 21:29:40 +0000 | [diff] [blame] | 61 | { |
| 62 | typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M; |
Eric Fiselier | 91a1565 | 2016-04-18 01:40:45 +0000 | [diff] [blame] | 63 | do_insert_rv_test<M>(); |
Howard Hinnant | 70342b9 | 2013-06-19 21:29:40 +0000 | [diff] [blame] | 64 | } |
Marshall Clow | 3426a86 | 2016-01-05 19:32:41 +0000 | [diff] [blame] | 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 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 93 | } |