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 | |
| 10 | // <unordered_map> |
| 11 | |
| 12 | // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 13 | // class Alloc = allocator<pair<const Key, T>>> |
| 14 | // class unordered_multimap |
| 15 | |
| 16 | // template <class P, |
| 17 | // class = typename enable_if<is_convertible<P, value_type>::value>::type> |
| 18 | // iterator insert(const_iterator p, P&& x); |
| 19 | |
Howard Hinnant | 5e57142 | 2013-08-23 20:10:18 +0000 | [diff] [blame] | 20 | #if _LIBCPP_DEBUG >= 1 |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 21 | #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) |
| 22 | #endif |
| 23 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | #include <unordered_map> |
| 25 | #include <cassert> |
| 26 | |
Marshall Clow | df00d5e | 2015-01-28 21:22:53 +0000 | [diff] [blame] | 27 | #include "MoveOnly.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 28 | #include "min_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 29 | |
| 30 | int main() |
| 31 | { |
| 32 | { |
| 33 | typedef std::unordered_multimap<double, int> C; |
| 34 | typedef C::iterator R; |
| 35 | typedef std::pair<double, short> P; |
| 36 | C c; |
| 37 | C::const_iterator e = c.end(); |
| 38 | R r = c.insert(e, P(3.5, 3)); |
| 39 | assert(c.size() == 1); |
| 40 | assert(r->first == 3.5); |
| 41 | assert(r->second == 3); |
| 42 | |
| 43 | r = c.insert(r, P(3.5, 4)); |
| 44 | assert(c.size() == 2); |
| 45 | assert(r->first == 3.5); |
| 46 | assert(r->second == 4); |
| 47 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 48 | r = c.insert(c.end(), P(4.5, 4)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 49 | assert(c.size() == 3); |
| 50 | assert(r->first == 4.5); |
| 51 | assert(r->second == 4); |
| 52 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 53 | r = c.insert(c.end(), P(5.5, 4)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 54 | assert(c.size() == 4); |
| 55 | assert(r->first == 5.5); |
| 56 | assert(r->second == 4); |
| 57 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 58 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | { |
| 60 | typedef std::unordered_multimap<MoveOnly, MoveOnly> C; |
| 61 | typedef C::iterator R; |
| 62 | typedef std::pair<MoveOnly, MoveOnly> P; |
| 63 | C c; |
| 64 | C::const_iterator e = c.end(); |
| 65 | R r = c.insert(e, P(3, 3)); |
| 66 | assert(c.size() == 1); |
| 67 | assert(r->first == 3); |
| 68 | assert(r->second == 3); |
| 69 | |
| 70 | r = c.insert(r, P(3, 4)); |
| 71 | assert(c.size() == 2); |
| 72 | assert(r->first == 3); |
| 73 | assert(r->second == 4); |
| 74 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 75 | r = c.insert(c.end(), P(4, 4)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 76 | assert(c.size() == 3); |
| 77 | assert(r->first == 4); |
| 78 | assert(r->second == 4); |
| 79 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 80 | r = c.insert(c.end(), P(5, 4)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 81 | assert(c.size() == 4); |
| 82 | assert(r->first == 5); |
| 83 | assert(r->second == 4); |
| 84 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 85 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 86 | #if __cplusplus >= 201103L |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 87 | { |
| 88 | typedef std::unordered_multimap<double, int, std::hash<double>, std::equal_to<double>, |
| 89 | min_allocator<std::pair<const double, int>>> C; |
| 90 | typedef C::iterator R; |
| 91 | typedef std::pair<double, short> P; |
| 92 | C c; |
| 93 | C::const_iterator e = c.end(); |
| 94 | R r = c.insert(e, P(3.5, 3)); |
| 95 | assert(c.size() == 1); |
| 96 | assert(r->first == 3.5); |
| 97 | assert(r->second == 3); |
| 98 | |
| 99 | r = c.insert(r, P(3.5, 4)); |
| 100 | assert(c.size() == 2); |
| 101 | assert(r->first == 3.5); |
| 102 | assert(r->second == 4); |
| 103 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 104 | r = c.insert(c.end(), P(4.5, 4)); |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 105 | assert(c.size() == 3); |
| 106 | assert(r->first == 4.5); |
| 107 | assert(r->second == 4); |
| 108 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 109 | r = c.insert(c.end(), P(5.5, 4)); |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 110 | assert(c.size() == 4); |
| 111 | assert(r->first == 5.5); |
| 112 | assert(r->second == 4); |
| 113 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 114 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 115 | { |
| 116 | typedef std::unordered_multimap<MoveOnly, MoveOnly, std::hash<MoveOnly>, std::equal_to<MoveOnly>, |
| 117 | min_allocator<std::pair<const MoveOnly, MoveOnly>>> C; |
| 118 | typedef C::iterator R; |
| 119 | typedef std::pair<MoveOnly, MoveOnly> P; |
| 120 | C c; |
| 121 | C::const_iterator e = c.end(); |
| 122 | R r = c.insert(e, P(3, 3)); |
| 123 | assert(c.size() == 1); |
| 124 | assert(r->first == 3); |
| 125 | assert(r->second == 3); |
| 126 | |
| 127 | r = c.insert(r, P(3, 4)); |
| 128 | assert(c.size() == 2); |
| 129 | assert(r->first == 3); |
| 130 | assert(r->second == 4); |
| 131 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 132 | r = c.insert(c.end(), P(4, 4)); |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 133 | assert(c.size() == 3); |
| 134 | assert(r->first == 4); |
| 135 | assert(r->second == 4); |
| 136 | |
Howard Hinnant | 3921364 | 2013-07-23 22:01:58 +0000 | [diff] [blame] | 137 | r = c.insert(c.end(), P(5, 4)); |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 138 | assert(c.size() == 4); |
| 139 | assert(r->first == 5); |
| 140 | assert(r->second == 4); |
| 141 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 142 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 5e57142 | 2013-08-23 20:10:18 +0000 | [diff] [blame] | 143 | #if _LIBCPP_DEBUG >= 1 |
Howard Hinnant | f890d9b | 2013-07-30 21:04:42 +0000 | [diff] [blame] | 144 | { |
| 145 | typedef std::unordered_multimap<double, int> C; |
| 146 | typedef C::iterator R; |
| 147 | typedef C::value_type P; |
| 148 | C c; |
| 149 | C c2; |
| 150 | C::const_iterator e = c2.end(); |
| 151 | R r = c.insert(e, P(3.5, 3)); |
| 152 | assert(false); |
| 153 | } |
| 154 | #endif |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 155 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 156 | } |