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 // transform_view() requires std::default_initializable<V> && 13 // std::default_initializable<F> = default; 14 15 #include <ranges> 16 17 #include <cassert> 18 #include <type_traits> 19 20 constexpr int buff[] = {1, 2, 3}; 21 22 struct DefaultConstructibleView : std::ranges::view_base { 23 constexpr DefaultConstructibleView() : begin_(buff), end_(buff + 3) { } 24 constexpr int const* begin() const { return begin_; } 25 constexpr int const* end() const { return end_; } 26 private: 27 int const* begin_; 28 int const* end_; 29 }; 30 31 struct DefaultConstructibleFunction { 32 int state_; 33 constexpr DefaultConstructibleFunction() : state_(100) { } 34 constexpr int operator()(int i) const { return i + state_; } 35 }; 36 37 struct NoDefaultCtrView : std::ranges::view_base { 38 NoDefaultCtrView() = delete; 39 int* begin() const; 40 int* end() const; 41 }; 42 43 struct NoDefaultFunction { 44 NoDefaultFunction() = delete; 45 constexpr int operator()(int i) const; 46 }; 47 48 constexpr bool test() { 49 { 50 std::ranges::transform_view<DefaultConstructibleView, DefaultConstructibleFunction> view; 51 assert(view.size() == 3); 52 assert(view[0] == 101); 53 assert(view[1] == 102); 54 assert(view[2] == 103); 55 } 56 57 { 58 std::ranges::transform_view<DefaultConstructibleView, DefaultConstructibleFunction> view = {}; 59 assert(view.size() == 3); 60 assert(view[0] == 101); 61 assert(view[1] == 102); 62 assert(view[2] == 103); 63 } 64 65 static_assert(!std::is_default_constructible_v<std::ranges::transform_view<NoDefaultCtrView, DefaultConstructibleFunction>>); 66 static_assert(!std::is_default_constructible_v<std::ranges::transform_view<DefaultConstructibleView, NoDefaultFunction>>); 67 static_assert(!std::is_default_constructible_v<std::ranges::transform_view<NoDefaultCtrView, NoDefaultFunction>>); 68 69 return true; 70 } 71 72 int main(int, char**) { 73 test(); 74 static_assert(test()); 75 76 return 0; 77 } 78