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 <ranges> 17 18 #include <cassert> 19 #include <utility> 20 21 #include "test_macros.h" 22 #include "types.h" 23 24 constexpr bool hasLValueQualifiedBase(auto&& view) { 25 return requires { view.base(); }; 26 } 27 28 constexpr bool test() { 29 int buf[8] = {1, 2, 3, 4, 5, 6, 7, 8}; 30 31 { 32 CopyableView view{buf, buf + 8}; 33 std::ranges::common_view<CopyableView> common(view); 34 assert(common.base().begin_ == buf); 35 assert(std::move(common).base().begin_ == buf); 36 37 ASSERT_SAME_TYPE(decltype(common.base()), CopyableView); 38 ASSERT_SAME_TYPE(decltype(std::move(common).base()), CopyableView); 39 static_assert(hasLValueQualifiedBase(common)); 40 } 41 42 { 43 MoveOnlyView view{buf, buf + 8}; 44 std::ranges::common_view<MoveOnlyView> common(std::move(view)); 45 assert(std::move(common).base().begin_ == buf); 46 47 ASSERT_SAME_TYPE(decltype(std::move(common).base()), MoveOnlyView); 48 static_assert(!hasLValueQualifiedBase(common)); 49 } 50 51 { 52 CopyableView view{buf, buf + 8}; 53 const std::ranges::common_view<CopyableView> common(view); 54 assert(common.base().begin_ == buf); 55 assert(std::move(common).base().begin_ == buf); 56 57 ASSERT_SAME_TYPE(decltype(common.base()), CopyableView); 58 ASSERT_SAME_TYPE(decltype(std::move(common).base()), CopyableView); 59 static_assert(hasLValueQualifiedBase(common)); 60 } 61 62 return true; 63 } 64 65 int main(int, char**) { 66 test(); 67 static_assert(test()); 68 69 return 0; 70 } 71