brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.3 KiB · d8ff8e7 Raw
141 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_multimap14 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_multimap<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() >= 7);44    assert(c.size() == 6);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    i         = c.begin();49    i->second = "ONE";50    assert(i->second == "ONE");51  }52  {53    typedef std::unordered_multimap<int, std::string> C;54    typedef std::pair<int, std::string> P;55    P a[] = {56        P(1, "one"),57        P(2, "two"),58        P(3, "three"),59        P(4, "four"),60        P(1, "four"),61        P(2, "four"),62    };63    const C c(a, a + sizeof(a) / sizeof(a[0]));64    assert(c.bucket_count() >= 7);65    assert(c.size() == 6);66    assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());67    assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());68    C::const_iterator i;69  }70#if TEST_STD_VER >= 1171  {72    typedef std::unordered_multimap<int,73                                    std::string,74                                    std::hash<int>,75                                    std::equal_to<int>,76                                    min_allocator<std::pair<const int, std::string>>>77        C;78    typedef std::pair<int, std::string> P;79    P a[] = {80        P(1, "one"),81        P(2, "two"),82        P(3, "three"),83        P(4, "four"),84        P(1, "four"),85        P(2, "four"),86    };87    C c(a, a + sizeof(a) / sizeof(a[0]));88    assert(c.bucket_count() >= 7);89    assert(c.size() == 6);90    assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());91    assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());92    C::iterator i;93    i         = c.begin();94    i->second = "ONE";95    assert(i->second == "ONE");96  }97  {98    typedef std::unordered_multimap<int,99                                    std::string,100                                    std::hash<int>,101                                    std::equal_to<int>,102                                    min_allocator<std::pair<const int, std::string>>>103        C;104    typedef std::pair<int, std::string> P;105    P a[] = {106        P(1, "one"),107        P(2, "two"),108        P(3, "three"),109        P(4, "four"),110        P(1, "four"),111        P(2, "four"),112    };113    const C c(a, a + sizeof(a) / sizeof(a[0]));114    assert(c.bucket_count() >= 7);115    assert(c.size() == 6);116    assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());117    assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());118    C::const_iterator i;119  }120#endif121#if TEST_STD_VER > 11122  { // N3644 testing123    typedef std::unordered_multimap<int, double> C;124    C::iterator ii1{}, ii2{};125    C::iterator ii4 = ii1;126    C::const_iterator cii{};127    assert(ii1 == ii2);128    assert(ii1 == ii4);129 130    assert(!(ii1 != ii2));131 132    assert((ii1 == cii));133    assert((cii == ii1));134    assert(!(ii1 != cii));135    assert(!(cii != ii1));136  }137#endif138 139  return 0;140}141