| 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 | // <unordered_map> |
| 10 | |
| 11 | // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, |
| 12 | // class Alloc = allocator<pair<const Key, T>>> |
| 13 | // class unordered_multimap |
| 14 | |
| 15 | // iterator begin() {return __table_.begin();} |
| 16 | // iterator end() {return __table_.end();} |
| 17 | // const_iterator begin() const {return __table_.begin();} |
| 18 | // const_iterator end() const {return __table_.end();} |
| 19 | // const_iterator cbegin() const {return __table_.begin();} |
| 20 | // const_iterator cend() const {return __table_.end();} |
| 21 | |
| 22 | #include <unordered_map> |
| 23 | #include <string> |
| 24 | #include <cassert> |
| 25 | |
| 26 | #include "test_macros.h" |
| 27 | |
| 28 | int main(int, char**) { |
| 29 | { |
| 30 | typedef std::unordered_multimap<int, std::string> C; |
| 31 | typedef std::pair<int, std::string> P; |
| 32 | P a[] = { |
| 33 | P(1, "one" ), |
| 34 | P(2, "two" ), |
| 35 | P(3, "three" ), |
| 36 | P(4, "four" ), |
| 37 | P(1, "four" ), |
| 38 | P(2, "four" ), |
| 39 | }; |
| 40 | C c(a, a + sizeof(a) / sizeof(a[0])); |
| 41 | LIBCPP_ASSERT(c.bucket_count() == 7); |
| 42 | assert(c.size() == 6); |
| 43 | assert(std::distance(c.begin(), c.end()) == c.size()); |
| 44 | assert(std::distance(c.cbegin(), c.cend()) == c.size()); |
| 45 | C::iterator i = c.begin(); |
| 46 | i->second = "ONE" ; |
| 47 | assert(i->second == "ONE" ); |
| 48 | i->first = 2; |
| 49 | } |
| 50 | { |
| 51 | typedef std::unordered_multimap<int, std::string> C; |
| 52 | typedef std::pair<int, std::string> P; |
| 53 | P a[] = { |
| 54 | P(1, "one" ), |
| 55 | P(2, "two" ), |
| 56 | P(3, "three" ), |
| 57 | P(4, "four" ), |
| 58 | P(1, "four" ), |
| 59 | P(2, "four" ), |
| 60 | }; |
| 61 | const C c(a, a + sizeof(a) / sizeof(a[0])); |
| 62 | LIBCPP_ASSERT(c.bucket_count() == 7); |
| 63 | assert(c.size() == 6); |
| 64 | assert(std::distance(c.begin(), c.end()) == c.size()); |
| 65 | assert(std::distance(c.cbegin(), c.cend()) == c.size()); |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |