14118858bSArthur O'Dwyer //===----------------------------------------------------------------------===//
24118858bSArthur O'Dwyer //
34118858bSArthur O'Dwyer // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44118858bSArthur O'Dwyer // See https://llvm.org/LICENSE.txt for license information.
54118858bSArthur O'Dwyer // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
64118858bSArthur O'Dwyer //
74118858bSArthur O'Dwyer //===----------------------------------------------------------------------===//
84118858bSArthur O'Dwyer
9*a7f9895cSLouis Dionne // UNSUPPORTED: no-filesystem
104118858bSArthur O'Dwyer
115024fe93SLouis Dionne // std::filesystem is unavailable prior to macOS 10.15
125024fe93SLouis Dionne // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}}
135024fe93SLouis Dionne
144118858bSArthur O'Dwyer // Make sure the various containers' iterators are not broken by the use of `std::rel_ops`.
154118858bSArthur O'Dwyer
164118858bSArthur O'Dwyer #include <utility> // for std::rel_ops
174118858bSArthur O'Dwyer
184118858bSArthur O'Dwyer #include <array>
194118858bSArthur O'Dwyer #include <deque>
204118858bSArthur O'Dwyer #include <forward_list>
214118858bSArthur O'Dwyer #include <list>
224118858bSArthur O'Dwyer #include <map>
234118858bSArthur O'Dwyer #include <set>
244118858bSArthur O'Dwyer #include <string>
254118858bSArthur O'Dwyer #include <unordered_map>
264118858bSArthur O'Dwyer #include <unordered_set>
274118858bSArthur O'Dwyer #include <vector>
284118858bSArthur O'Dwyer
294118858bSArthur O'Dwyer #include "test_macros.h"
304118858bSArthur O'Dwyer
314118858bSArthur O'Dwyer #if TEST_STD_VER >= 11
324118858bSArthur O'Dwyer #include "filesystem_include.h"
334118858bSArthur O'Dwyer #endif
344118858bSArthur O'Dwyer
354118858bSArthur O'Dwyer #if TEST_STD_VER >= 17
364118858bSArthur O'Dwyer #include <string_view>
374118858bSArthur O'Dwyer #endif
384118858bSArthur O'Dwyer
394118858bSArthur O'Dwyer #if TEST_STD_VER >= 20
404118858bSArthur O'Dwyer #include <span>
414118858bSArthur O'Dwyer #endif
424118858bSArthur O'Dwyer
434118858bSArthur O'Dwyer using namespace std::rel_ops;
444118858bSArthur O'Dwyer
454118858bSArthur O'Dwyer template<class It, class ConstIt>
test_eq(It it,ConstIt cit)464118858bSArthur O'Dwyer void test_eq(It it, ConstIt cit) {
474118858bSArthur O'Dwyer (void)(it == it);
484118858bSArthur O'Dwyer (void)(it != it);
494118858bSArthur O'Dwyer (void)(it == cit);
504118858bSArthur O'Dwyer (void)(it != cit);
514118858bSArthur O'Dwyer (void)(cit == it);
524118858bSArthur O'Dwyer (void)(cit != it);
534118858bSArthur O'Dwyer (void)(cit == cit);
544118858bSArthur O'Dwyer (void)(cit != cit);
554118858bSArthur O'Dwyer }
564118858bSArthur O'Dwyer
574118858bSArthur O'Dwyer template<class It, class ConstIt>
test_lt(It it,ConstIt cit)584118858bSArthur O'Dwyer void test_lt(It it, ConstIt cit) {
594118858bSArthur O'Dwyer (void)(it < it);
604118858bSArthur O'Dwyer (void)(it <= it);
614118858bSArthur O'Dwyer (void)(it > it);
624118858bSArthur O'Dwyer (void)(it >= it);
634118858bSArthur O'Dwyer (void)(it < cit);
644118858bSArthur O'Dwyer (void)(it <= cit);
654118858bSArthur O'Dwyer (void)(it > cit);
664118858bSArthur O'Dwyer (void)(it >= cit);
674118858bSArthur O'Dwyer (void)(cit < it);
684118858bSArthur O'Dwyer (void)(cit <= it);
694118858bSArthur O'Dwyer (void)(cit > it);
704118858bSArthur O'Dwyer (void)(cit >= it);
714118858bSArthur O'Dwyer (void)(cit < cit);
724118858bSArthur O'Dwyer (void)(cit <= cit);
734118858bSArthur O'Dwyer (void)(cit > cit);
744118858bSArthur O'Dwyer (void)(cit >= cit);
754118858bSArthur O'Dwyer
764118858bSArthur O'Dwyer // Test subtraction too, even though std::rel_ops shouldn't affect it.
774118858bSArthur O'Dwyer
784118858bSArthur O'Dwyer (void)(it - it);
794118858bSArthur O'Dwyer (void)(it - cit);
804118858bSArthur O'Dwyer (void)(cit - it);
814118858bSArthur O'Dwyer (void)(cit - cit);
824118858bSArthur O'Dwyer }
834118858bSArthur O'Dwyer
844118858bSArthur O'Dwyer template<class Container>
test_forward()854118858bSArthur O'Dwyer void test_forward() {
864118858bSArthur O'Dwyer // There is no need to distinguish "forward" from "bidirectional."
874118858bSArthur O'Dwyer // libc++ already can't handle `c.rbegin() >= c.rbegin()` in the
884118858bSArthur O'Dwyer // presence of std::rel_ops, and neither can Microsoft nor libstdc++.
894118858bSArthur O'Dwyer
904118858bSArthur O'Dwyer Container c;
914118858bSArthur O'Dwyer typename Container::iterator it = c.begin();
924118858bSArthur O'Dwyer typename Container::const_iterator cit = c.begin();
934118858bSArthur O'Dwyer test_eq(it, cit);
944118858bSArthur O'Dwyer }
954118858bSArthur O'Dwyer
964118858bSArthur O'Dwyer template<class Container>
test_random_access()974118858bSArthur O'Dwyer void test_random_access() {
984118858bSArthur O'Dwyer Container c;
994118858bSArthur O'Dwyer typename Container::iterator it = c.begin();
1004118858bSArthur O'Dwyer typename Container::const_iterator cit = c.begin();
1014118858bSArthur O'Dwyer test_eq(it, cit);
1024118858bSArthur O'Dwyer test_lt(it, cit);
1034118858bSArthur O'Dwyer }
1044118858bSArthur O'Dwyer
1054118858bSArthur O'Dwyer template void test_random_access<std::array<int, 10> >();
1064118858bSArthur O'Dwyer template void test_random_access<std::deque<int> >();
1074118858bSArthur O'Dwyer template void test_forward<std::forward_list<int> >();
1084118858bSArthur O'Dwyer template void test_forward<std::list<int> >();
1094118858bSArthur O'Dwyer template void test_forward<std::map<int, int> >();
1104118858bSArthur O'Dwyer template void test_forward<std::multimap<int, int> >();
1114118858bSArthur O'Dwyer template void test_forward<std::multiset<int> >();
1124118858bSArthur O'Dwyer template void test_forward<std::set<int> >();
1134118858bSArthur O'Dwyer template void test_random_access<std::string>();
1144118858bSArthur O'Dwyer template void test_forward<std::unordered_map<int, int> >();
1154118858bSArthur O'Dwyer template void test_forward<std::unordered_multimap<int, int> >();
1164118858bSArthur O'Dwyer template void test_forward<std::unordered_multiset<int> >();
1174118858bSArthur O'Dwyer template void test_forward<std::unordered_set<int> >();
1184118858bSArthur O'Dwyer template void test_random_access<std::vector<int> >();
1194118858bSArthur O'Dwyer
1204118858bSArthur O'Dwyer #if TEST_STD_VER >= 11
test_directory_iterators()1214118858bSArthur O'Dwyer void test_directory_iterators() {
1224118858bSArthur O'Dwyer fs::directory_iterator it;
1234118858bSArthur O'Dwyer test_eq(it, it);
1244118858bSArthur O'Dwyer
1254118858bSArthur O'Dwyer fs::recursive_directory_iterator rdit;
1264118858bSArthur O'Dwyer test_eq(rdit, rdit);
1274118858bSArthur O'Dwyer }
1284118858bSArthur O'Dwyer
1294118858bSArthur O'Dwyer template void test_forward<fs::path>();
1304118858bSArthur O'Dwyer #endif
1314118858bSArthur O'Dwyer
1324118858bSArthur O'Dwyer #if TEST_STD_VER >= 17
1334118858bSArthur O'Dwyer template void test_random_access<std::string_view>();
1344118858bSArthur O'Dwyer #endif
1354118858bSArthur O'Dwyer
1364118858bSArthur O'Dwyer #if TEST_STD_VER >= 20
test_span()1374118858bSArthur O'Dwyer void test_span() {
1384118858bSArthur O'Dwyer std::span<int> c;
1394118858bSArthur O'Dwyer std::span<int>::iterator it = c.begin(); // span has no const_iterator
1404118858bSArthur O'Dwyer test_eq(it, it);
1414118858bSArthur O'Dwyer test_lt(it, it);
1424118858bSArthur O'Dwyer }
1434118858bSArthur O'Dwyer #endif
144