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_map |
| 15 | |
| 16 | // mapped_type& operator[](const key_type& k); |
| 17 | |
| 18 | #include <unordered_map> |
| 19 | #include <string> |
| 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" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | |
| 25 | int main() |
| 26 | { |
| 27 | { |
| 28 | typedef std::unordered_map<int, std::string> C; |
| 29 | typedef std::pair<int, std::string> P; |
| 30 | P a[] = |
| 31 | { |
| 32 | P(1, "one"), |
| 33 | P(2, "two"), |
| 34 | P(3, "three"), |
| 35 | P(4, "four"), |
| 36 | P(1, "four"), |
| 37 | P(2, "four"), |
| 38 | }; |
| 39 | C c(a, a + sizeof(a)/sizeof(a[0])); |
| 40 | assert(c.size() == 4); |
| 41 | c[1] = "ONE"; |
| 42 | assert(c.at(1) == "ONE"); |
| 43 | c[11] = "eleven"; |
| 44 | assert(c.size() == 5); |
| 45 | assert(c.at(11) == "eleven"); |
| 46 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 47 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | { |
| 49 | typedef std::unordered_map<MoveOnly, std::string> C; |
| 50 | typedef std::pair<int, std::string> P; |
| 51 | P a[] = |
| 52 | { |
| 53 | P(1, "one"), |
| 54 | P(2, "two"), |
| 55 | P(3, "three"), |
| 56 | P(4, "four"), |
| 57 | P(1, "four"), |
| 58 | P(2, "four"), |
| 59 | }; |
| 60 | C c(a, a + sizeof(a)/sizeof(a[0])); |
| 61 | assert(c.size() == 4); |
| 62 | c[1] = "ONE"; |
| 63 | assert(c.at(1) == "ONE"); |
| 64 | c[11] = "eleven"; |
| 65 | assert(c.size() == 5); |
| 66 | assert(c.at(11) == "eleven"); |
| 67 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 68 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 69 | #if __cplusplus >= 201103L |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 70 | { |
| 71 | typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, |
| 72 | min_allocator<std::pair<const int, std::string>>> C; |
| 73 | typedef std::pair<int, std::string> P; |
| 74 | P a[] = |
| 75 | { |
| 76 | P(1, "one"), |
| 77 | P(2, "two"), |
| 78 | P(3, "three"), |
| 79 | P(4, "four"), |
| 80 | P(1, "four"), |
| 81 | P(2, "four"), |
| 82 | }; |
| 83 | C c(a, a + sizeof(a)/sizeof(a[0])); |
| 84 | assert(c.size() == 4); |
| 85 | c[1] = "ONE"; |
| 86 | assert(c.at(1) == "ONE"); |
| 87 | c[11] = "eleven"; |
| 88 | assert(c.size() == 5); |
| 89 | assert(c.at(11) == "eleven"); |
| 90 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 91 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 92 | { |
| 93 | typedef std::unordered_map<MoveOnly, std::string, std::hash<MoveOnly>, std::equal_to<MoveOnly>, |
| 94 | min_allocator<std::pair<const MoveOnly, std::string>>> C; |
| 95 | typedef std::pair<int, std::string> P; |
| 96 | P a[] = |
| 97 | { |
| 98 | P(1, "one"), |
| 99 | P(2, "two"), |
| 100 | P(3, "three"), |
| 101 | P(4, "four"), |
| 102 | P(1, "four"), |
| 103 | P(2, "four"), |
| 104 | }; |
| 105 | C c(a, a + sizeof(a)/sizeof(a[0])); |
| 106 | assert(c.size() == 4); |
| 107 | c[1] = "ONE"; |
| 108 | assert(c.at(1) == "ONE"); |
| 109 | c[11] = "eleven"; |
| 110 | assert(c.size() == 5); |
| 111 | assert(c.at(11) == "eleven"); |
| 112 | } |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 113 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 7a6b7ce | 2013-06-22 15:21:29 +0000 | [diff] [blame] | 114 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 | } |