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