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 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 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_map |
| 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 | |
| 20 | #include <unordered_map> |
| 21 | #include <cassert> |
| 22 | |
| 23 | #include "../../../MoveOnly.h" |
| 24 | |
| 25 | int main() |
| 26 | { |
| 27 | { |
| 28 | typedef std::unordered_map<double, int> C; |
| 29 | typedef C::iterator R; |
| 30 | typedef std::pair<double, short> P; |
| 31 | C c; |
| 32 | C::const_iterator e = c.end(); |
| 33 | R r = c.insert(e, P(3.5, 3)); |
| 34 | assert(c.size() == 1); |
| 35 | assert(r->first == 3.5); |
| 36 | assert(r->second == 3); |
| 37 | |
| 38 | r = c.insert(e, P(3.5, 4)); |
| 39 | assert(c.size() == 1); |
| 40 | assert(r->first == 3.5); |
| 41 | assert(r->second == 3); |
| 42 | |
| 43 | r = c.insert(e, P(4.5, 4)); |
| 44 | assert(c.size() == 2); |
| 45 | assert(r->first == 4.5); |
| 46 | assert(r->second == 4); |
| 47 | |
| 48 | r = c.insert(e, P(5.5, 4)); |
| 49 | assert(c.size() == 3); |
| 50 | assert(r->first == 5.5); |
| 51 | assert(r->second == 4); |
| 52 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 53 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 54 | { |
| 55 | typedef std::unordered_map<MoveOnly, MoveOnly> C; |
| 56 | typedef C::iterator R; |
| 57 | typedef std::pair<MoveOnly, MoveOnly> P; |
| 58 | C c; |
| 59 | C::const_iterator e = c.end(); |
| 60 | R r = c.insert(e, P(3, 3)); |
| 61 | assert(c.size() == 1); |
| 62 | assert(r->first == 3); |
| 63 | assert(r->second == 3); |
| 64 | |
| 65 | r = c.insert(e, P(3, 4)); |
| 66 | assert(c.size() == 1); |
| 67 | assert(r->first == 3); |
| 68 | assert(r->second == 3); |
| 69 | |
| 70 | r = c.insert(e, P(4, 4)); |
| 71 | assert(c.size() == 2); |
| 72 | assert(r->first == 4); |
| 73 | assert(r->second == 4); |
| 74 | |
| 75 | r = c.insert(e, P(5, 4)); |
| 76 | assert(c.size() == 3); |
| 77 | assert(r->first == 5); |
| 78 | assert(r->second == 4); |
| 79 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 80 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 81 | } |