| 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 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 10 | |
| 11 | // <flat_map> |
| 12 | |
| 13 | // class flat_multimap |
| 14 | |
| 15 | // iterator begin() noexcept; |
| 16 | // const_iterator begin() const noexcept |
| 17 | // iterator end() noexcept; |
| 18 | // const_iterator end() const noexcept; |
| 19 | // |
| 20 | // const_iterator cbegin() const noexcept; |
| 21 | // const_iterator cend() const noexcept; |
| 22 | |
| 23 | #include <cassert> |
| 24 | #include <cstddef> |
| 25 | #include <deque> |
| 26 | #include <flat_map> |
| 27 | #include <functional> |
| 28 | #include <string> |
| 29 | |
| 30 | #include "MinSequenceContainer.h" |
| 31 | #include "test_macros.h" |
| 32 | #include "min_allocator.h" |
| 33 | |
| 34 | template <class KeyContainer, class ValueContainer> |
| 35 | void test() { |
| 36 | using Key = typename KeyContainer::value_type; |
| 37 | using Value = typename ValueContainer::value_type; |
| 38 | using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>; |
| 39 | |
| 40 | M m = {{1, 'a'}, {1, 'z'}, {2, 'b'}, {3, 'a'}, {3, 'b'}, {3, 'c'}, {4, 'd'}}; |
| 41 | const M& cm = m; |
| 42 | ASSERT_SAME_TYPE(decltype(m.begin()), typename M::iterator); |
| 43 | ASSERT_SAME_TYPE(decltype(m.cbegin()), typename M::const_iterator); |
| 44 | ASSERT_SAME_TYPE(decltype(cm.begin()), typename M::const_iterator); |
| 45 | ASSERT_SAME_TYPE(decltype(m.end()), typename M::iterator); |
| 46 | ASSERT_SAME_TYPE(decltype(m.cend()), typename M::const_iterator); |
| 47 | ASSERT_SAME_TYPE(decltype(cm.end()), typename M::const_iterator); |
| 48 | static_assert(noexcept(m.begin())); |
| 49 | static_assert(noexcept(cm.begin())); |
| 50 | static_assert(noexcept(m.cbegin())); |
| 51 | static_assert(noexcept(m.end())); |
| 52 | static_assert(noexcept(cm.end())); |
| 53 | static_assert(noexcept(m.cend())); |
| 54 | assert(m.size() == 7); |
| 55 | assert(std::distance(m.begin(), m.end()) == 7); |
| 56 | assert(std::distance(cm.begin(), cm.end()) == 7); |
| 57 | assert(std::distance(m.cbegin(), m.cend()) == 7); |
| 58 | typename M::iterator i; // default-construct |
| 59 | i = m.begin(); // move-assignment |
| 60 | typename M::const_iterator k = i; // converting constructor |
| 61 | assert(i == k); // comparison |
| 62 | assert(i->first == 1); // operator-> |
| 63 | assert(i->second == 'a'); // operator-> |
| 64 | ++i; // pre-increment |
| 65 | assert(i->first == 1); // operator-> |
| 66 | assert(i->second == 'z'); // operator-> |
| 67 | i = i + 3; // operator+ |
| 68 | assert((*i).first == 3); // operator* |
| 69 | assert((*i).second == 'b'); // operator* |
| 70 | i += 3; // operator+= |
| 71 | assert(i == m.end()); // operator== |
| 72 | --i; // pre-decrement |
| 73 | assert(i->first == 4); // operator-> |
| 74 | assert(i->second == 'd'); // operator-> |
| 75 | i = i - 2; // operator- |
| 76 | assert(i->first == 3); // operator-> |
| 77 | assert(i->second == 'b'); // operator-> |
| 78 | i -= 2; // operator-= |
| 79 | assert(i > m.begin()); // operator> |
| 80 | } |
| 81 | |
| 82 | int main(int, char**) { |
| 83 | test<std::vector<int>, std::vector<char>>(); |
| 84 | test<std::deque<int>, std::vector<char>>(); |
| 85 | test<MinSequenceContainer<int>, MinSequenceContainer<char>>(); |
| 86 | test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>(); |
| 87 | |
| 88 | { |
| 89 | // N3644 testing |
| 90 | using C = std::flat_multimap<int, char>; |
| 91 | C::iterator ii1{}, ii2{}; |
| 92 | C::iterator ii4 = ii1; |
| 93 | C::const_iterator cii{}; |
| 94 | assert(ii1 == ii2); |
| 95 | assert(ii1 == ii4); |
| 96 | assert(!(ii1 != ii2)); |
| 97 | |
| 98 | assert((ii1 == cii)); |
| 99 | assert((cii == ii1)); |
| 100 | assert(!(ii1 != cii)); |
| 101 | assert(!(cii != ii1)); |
| 102 | } |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |