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: libcpp-no-concepts 11 // UNSUPPORTED: libcpp-has-no-incomplete-ranges 12 13 // constexpr V base() const& requires copy_constructible<V>; 14 // constexpr V base() &&; 15 16 #include <cassert> 17 #include <ranges> 18 19 #include "test_macros.h" 20 #include "types.h" 21 22 constexpr bool hasLValueQualifiedBase(auto&& view) { 23 return requires { view.base(); }; 24 } 25 26 constexpr bool test() { 27 int buffer[4][4] = {{1111, 2222, 3333, 4444}, {555, 666, 777, 888}, {99, 1010, 1111, 1212}, {13, 14, 15, 16}}; 28 29 { 30 ChildView children[4] = {ChildView(buffer[0]), ChildView(buffer[1]), ChildView(buffer[2]), ChildView(buffer[3])}; 31 auto jv = std::ranges::join_view(ParentView{children}); 32 assert(std::move(jv).base().ptr_ == children); 33 34 static_assert(!hasLValueQualifiedBase(jv)); 35 ASSERT_SAME_TYPE(decltype(std::move(jv).base()), ParentView<ChildView>); 36 } 37 38 { 39 std::ranges::join_view jv(buffer); 40 assert(jv.base().base() == buffer + 0); 41 42 static_assert(hasLValueQualifiedBase(jv)); 43 ASSERT_SAME_TYPE(decltype(jv.base()), std::ranges::ref_view<int [4][4]>); 44 } 45 46 { 47 const std::ranges::join_view jv(buffer); 48 assert(jv.base().base() == buffer + 0); 49 50 static_assert(hasLValueQualifiedBase(jv)); 51 ASSERT_SAME_TYPE(decltype(jv.base()), std::ranges::ref_view<int [4][4]>); 52 } 53 54 return true; 55 } 56 57 int main(int, char**) { 58 test(); 59 static_assert(test()); 60 61 return 0; 62 } 63