Debian Codegraph @

libcxx/test/std/ranges/iterator_robust_against_adl.compile.pass.cpp

raw
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
10
11 // ADL call with nested iterators of views should not look up base's view's
12 // namespace
13
14 #include <ranges>
15 #include <tuple>
16
17 #include "test_macros.h"
18
19 #ifndef TEST_HAS_NO_LOCALIZATION
20 #include <istream>
21 #endif
22 namespace adl {
23
24 struct BaseView : std::ranges::view_base {
25 int* begin() const;
26 int* end() const;
27 };
28
29 struct TupleView : std::ranges::view_base {
30 std::tuple<int>* begin() const;
31 std::tuple<int>* end() const;
32 };
33
34 struct NestedView : std::ranges::view_base {
35 BaseView* begin() const;
36 BaseView* end() const;
37 };
38
39 struct Pred {
40 bool operator()(const auto&...) const;
41 };
42
43 struct Sentinel {
44 bool operator==(const auto&) const;
45 };
46
47 struct Value {
48 friend std::istream& operator>>(std::istream&, Value);
49 };
50
51 void adl_func(const auto&);
52
53 } // namespace adl
54
55 template <class View>
56 concept CanFindADLFunc = requires(std::ranges::iterator_t<View> it) { adl_func(it); };
57
58 static_assert(!CanFindADLFunc<std::ranges::elements_view<adl::TupleView, 0>>);
59 static_assert(!CanFindADLFunc<std::ranges::filter_view<adl::BaseView, adl::Pred>>);
60 static_assert(!CanFindADLFunc<std::ranges::iota_view<int, adl::Sentinel>>);
61
62 #ifndef TEST_HAS_NO_LOCALIZATION
63 static_assert(!CanFindADLFunc<std::ranges::istream_view<adl::Value>>);
64 #endif
65
66 static_assert(!CanFindADLFunc<std::ranges::join_view<adl::NestedView>>);
67
68 static_assert(!CanFindADLFunc<std::ranges::lazy_split_view<adl::BaseView, adl::BaseView>>);
69 using InnerRange =
70 typename std::ranges::iterator_t<std::ranges::lazy_split_view<adl::BaseView, adl::BaseView>>::value_type;
71 static_assert(!CanFindADLFunc<InnerRange >);
72
73 static_assert(!CanFindADLFunc<std::ranges::split_view<adl::BaseView, adl::BaseView>>);
74 static_assert(!CanFindADLFunc<std::ranges::transform_view<adl::BaseView, adl::Pred>>);
75
76 #if TEST_STD_VER >= 23
77 static_assert(!CanFindADLFunc<std::ranges::zip_view<adl::BaseView>>);
78 #endif