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-has-no-incomplete-ranges 11 12 // take_view() requires default_initializable<V> = default; 13 14 #include <ranges> 15 #include <cassert> 16 17 int buff[8] = {1, 2, 3, 4, 5, 6, 7, 8}; 18 19 struct DefaultConstructible : std::ranges::view_base { 20 constexpr DefaultConstructible() : begin_(buff), end_(buff + 8) { } 21 constexpr int const* begin() const { return begin_; } 22 constexpr int const* end() const { return end_; } 23 private: 24 int const* begin_; 25 int const* end_; 26 }; 27 28 struct NonDefaultConstructible : std::ranges::view_base { 29 NonDefaultConstructible() = delete; 30 int* begin() const; 31 int* end() const; 32 }; 33 34 constexpr bool test() { 35 { 36 std::ranges::take_view<DefaultConstructible> tv; 37 assert(tv.begin() == buff); 38 assert(tv.size() == 0); 39 } 40 41 // Test SFINAE-friendliness 42 { 43 static_assert( std::is_default_constructible_v<std::ranges::take_view<DefaultConstructible>>); 44 static_assert(!std::is_default_constructible_v<std::ranges::take_view<NonDefaultConstructible>>); 45 } 46 47 return true; 48 } 49 50 int main(int, char**) { 51 test(); 52 static_assert(test()); 53 54 return 0; 55 } 56