1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: libcpp-has-no-filesystem-library
// std::filesystem is unavailable prior to macOS 10.15
// XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}}
// Make sure the various containers' iterators are not broken by the use of `std::rel_ops`.
#include <utility> // for std::rel_ops
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "test_macros.h"
#if TEST_STD_VER >= 11
#include "filesystem_include.h"
#endif
#if TEST_STD_VER >= 17
#include <string_view>
#endif
#if TEST_STD_VER >= 20
#include <span>
#endif
using namespace std::rel_ops;
template<class It, class ConstIt>
void test_eq(It it, ConstIt cit) {
(void)(it == it);
(void)(it != it);
(void)(it == cit);
(void)(it != cit);
(void)(cit == it);
(void)(cit != it);
(void)(cit == cit);
(void)(cit != cit);
}
template<class It, class ConstIt>
void test_lt(It it, ConstIt cit) {
(void)(it < it);
(void)(it <= it);
(void)(it > it);
(void)(it >= it);
(void)(it < cit);
(void)(it <= cit);
(void)(it > cit);
(void)(it >= cit);
(void)(cit < it);
(void)(cit <= it);
(void)(cit > it);
(void)(cit >= it);
(void)(cit < cit);
(void)(cit <= cit);
(void)(cit > cit);
(void)(cit >= cit);
// Test subtraction too, even though std::rel_ops shouldn't affect it.
(void)(it - it);
(void)(it - cit);
(void)(cit - it);
(void)(cit - cit);
}
template<class Container>
void test_forward() {
// There is no need to distinguish "forward" from "bidirectional."
// libc++ already can't handle `c.rbegin() >= c.rbegin()` in the
// presence of std::rel_ops, and neither can Microsoft nor libstdc++.
Container c;
typename Container::iterator it = c.begin();
typename Container::const_iterator cit = c.begin();
test_eq(it, cit);
}
template<class Container>
void test_random_access() {
Container c;
typename Container::iterator it = c.begin();
typename Container::const_iterator cit = c.begin();
test_eq(it, cit);
test_lt(it, cit);
}
template void test_random_access<std::array<int, 10> >();
template void test_random_access<std::deque<int> >();
template void test_forward<std::forward_list<int> >();
template void test_forward<std::list<int> >();
template void test_forward<std::map<int, int> >();
template void test_forward<std::multimap<int, int> >();
template void test_forward<std::multiset<int> >();
template void test_forward<std::set<int> >();
template void test_random_access<std::string>();
template void test_forward<std::unordered_map<int, int> >();
template void test_forward<std::unordered_multimap<int, int> >();
template void test_forward<std::unordered_multiset<int> >();
template void test_forward<std::unordered_set<int> >();
template void test_random_access<std::vector<int> >();
#if TEST_STD_VER >= 11
void test_directory_iterators() {
fs::directory_iterator it;
test_eq(it, it);
fs::recursive_directory_iterator rdit;
test_eq(rdit, rdit);
}
template void test_forward<fs::path>();
#endif
#if TEST_STD_VER >= 17
template void test_random_access<std::string_view>();
#endif
#if TEST_STD_VER >= 20
void test_span() {
std::span<int> c;
std::span<int>::iterator it = c.begin(); // span has no const_iterator
test_eq(it, it);
test_lt(it, it);
}
#endif
|