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