135 lines · cpp
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-exception6//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_map14 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#include <cstddef>26 27#include "test_macros.h"28#include "min_allocator.h"29 30int main(int, char**) {31 {32 typedef std::unordered_map<int, std::string> C;33 typedef std::pair<int, std::string> P;34 P a[] = {35 P(1, "one"),36 P(2, "two"),37 P(3, "three"),38 P(4, "four"),39 P(1, "four"),40 P(2, "four"),41 };42 C c(a, a + sizeof(a) / sizeof(a[0]));43 assert(c.bucket_count() >= 5);44 assert(c.size() == 4);45 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());46 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());47 C::iterator i;48 }49 {50 typedef std::unordered_map<int, std::string> C;51 typedef std::pair<int, std::string> P;52 P a[] = {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 const C c(a, a + sizeof(a) / sizeof(a[0]));61 assert(c.bucket_count() >= 5);62 assert(c.size() == 4);63 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());64 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());65 C::const_iterator i;66 }67#if TEST_STD_VER >= 1168 {69 typedef std::unordered_map<int,70 std::string,71 std::hash<int>,72 std::equal_to<int>,73 min_allocator<std::pair<const int, std::string>>>74 C;75 typedef std::pair<int, std::string> P;76 P a[] = {77 P(1, "one"),78 P(2, "two"),79 P(3, "three"),80 P(4, "four"),81 P(1, "four"),82 P(2, "four"),83 };84 C c(a, a + sizeof(a) / sizeof(a[0]));85 assert(c.bucket_count() >= 5);86 assert(c.size() == 4);87 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());88 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());89 C::iterator i;90 }91 {92 typedef std::unordered_map<int,93 std::string,94 std::hash<int>,95 std::equal_to<int>,96 min_allocator<std::pair<const int, std::string>>>97 C;98 typedef std::pair<int, std::string> P;99 P a[] = {100 P(1, "one"),101 P(2, "two"),102 P(3, "three"),103 P(4, "four"),104 P(1, "four"),105 P(2, "four"),106 };107 const C c(a, a + sizeof(a) / sizeof(a[0]));108 assert(c.bucket_count() >= 5);109 assert(c.size() == 4);110 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());111 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());112 C::const_iterator i;113 }114#endif115#if TEST_STD_VER > 11116 { // N3644 testing117 typedef std::unordered_map<int, double> C;118 C::iterator ii1{}, ii2{};119 C::iterator ii4 = ii1;120 C::const_iterator cii{};121 assert(ii1 == ii2);122 assert(ii1 == ii4);123 124 assert(!(ii1 != ii2));125 126 assert((ii1 == cii));127 assert((cii == ii1));128 assert(!(ii1 != cii));129 assert(!(cii != ii1));130 }131#endif132 133 return 0;134}135