56 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// take_view() requires default_initializable<V> = default;12 13#include <cassert>14#include <ranges>15#include <type_traits>16 17int buff[8] = {1, 2, 3, 4, 5, 6, 7, 8};18 19struct 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_; }23private:24 int const* begin_;25 int const* end_;26};27 28struct NonDefaultConstructible : std::ranges::view_base {29 NonDefaultConstructible() = delete;30 int* begin() const;31 int* end() const;32};33 34constexpr 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-friendliness42 {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 50int main(int, char**) {51 test();52 static_assert(test());53 54 return 0;55}56