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