| 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 | // reverse_iterator rbegin() noexcept; |
| 16 | // const_reverse_iterator rbegin() const noexcept; |
| 17 | // reverse_iterator rend() noexcept; |
| 18 | // const_reverse_iterator rend() const noexcept; |
| 19 | // |
| 20 | // const_reverse_iterator crbegin() const noexcept; |
| 21 | // const_reverse_iterator crend() const noexcept; |
| 22 | |
| 23 | #include <cassert> |
| 24 | #include <deque> |
| 25 | #include <flat_map> |
| 26 | #include <functional> |
| 27 | |
| 28 | #include <iterator> |
| 29 | |
| 30 | #include "test_macros.h" |
| 31 | |
| 32 | int main(int, char**) { |
| 33 | { |
| 34 | using M = std::flat_multimap<int, char, std::less<int>, std::deque<int>, std::deque<char>>; |
| 35 | M m = {{1, 'a'}, {1, 'b'}, {2, 'c'}, {2, 'd'}, {3, 'e'}, {3, 'f'}, {4, 'g'}, {4, 'h'}}; |
| 36 | const M& cm = m; |
| 37 | ASSERT_SAME_TYPE(decltype(m.rbegin()), M::reverse_iterator); |
| 38 | ASSERT_SAME_TYPE(decltype(m.crbegin()), M::const_reverse_iterator); |
| 39 | ASSERT_SAME_TYPE(decltype(cm.rbegin()), M::const_reverse_iterator); |
| 40 | ASSERT_SAME_TYPE(decltype(m.rend()), M::reverse_iterator); |
| 41 | ASSERT_SAME_TYPE(decltype(m.crend()), M::const_reverse_iterator); |
| 42 | ASSERT_SAME_TYPE(decltype(cm.rend()), M::const_reverse_iterator); |
| 43 | static_assert(noexcept(m.rbegin())); |
| 44 | static_assert(noexcept(cm.rbegin())); |
| 45 | static_assert(noexcept(m.crbegin())); |
| 46 | static_assert(noexcept(m.rend())); |
| 47 | static_assert(noexcept(cm.rend())); |
| 48 | static_assert(noexcept(m.crend())); |
| 49 | assert(m.size() == 8); |
| 50 | assert(std::distance(m.rbegin(), m.rend()) == 8); |
| 51 | assert(std::distance(cm.rbegin(), cm.rend()) == 8); |
| 52 | assert(std::distance(m.crbegin(), m.crend()) == 8); |
| 53 | assert(std::distance(cm.crbegin(), cm.crend()) == 8); |
| 54 | M::reverse_iterator i; // default-construct |
| 55 | ASSERT_SAME_TYPE(decltype(i->first), const int&); |
| 56 | ASSERT_SAME_TYPE(decltype(i->second), char&); |
| 57 | i = m.rbegin(); // move-assignment |
| 58 | M::const_reverse_iterator k = i; // converting constructor |
| 59 | assert(i == k); // comparison |
| 60 | for (int j = 8; j >= 1; --j, ++i) { // pre-increment |
| 61 | assert(i->first == (j + 1) / 2); // operator-> |
| 62 | assert(i->second == 'a' + j - 1); |
| 63 | } |
| 64 | assert(i == m.rend()); |
| 65 | for (int j = 1; j <= 8; ++j) { |
| 66 | --i; // pre-decrement |
| 67 | assert((*i).first == (j + 1) / 2); |
| 68 | assert((*i).second == 'a' + j - 1); |
| 69 | } |
| 70 | assert(i == m.rbegin()); |
| 71 | } |
| 72 | { |
| 73 | // N3644 testing |
| 74 | using C = std::flat_multimap<int, char>; |
| 75 | C::reverse_iterator ii1{}, ii2{}; |
| 76 | C::reverse_iterator ii4 = ii1; |
| 77 | C::const_reverse_iterator cii{}; |
| 78 | assert(ii1 == ii2); |
| 79 | assert(ii1 == ii4); |
| 80 | assert(!(ii1 != ii2)); |
| 81 | |
| 82 | assert((ii1 == cii)); |
| 83 | assert((cii == ii1)); |
| 84 | assert(!(ii1 != cii)); |
| 85 | assert(!(cii != ii1)); |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |