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 // single_view() requires default_initializable<T> = default;
14 
15 #include <ranges>
16 #include <cassert>
17 
18 #include "test_macros.h"
19 
20 struct BigType { char buffer[64] = {10}; };
21 
22 template<bool DefaultCtorEnabled>
23 struct IsDefaultConstructible {
24   IsDefaultConstructible() requires DefaultCtorEnabled = default;
25 };
26 
27 constexpr bool test() {
28   static_assert( std::default_initializable<std::ranges::single_view<IsDefaultConstructible<true>>>);
29   static_assert(!std::default_initializable<std::ranges::single_view<IsDefaultConstructible<false>>>);
30 
31   {
32     std::ranges::single_view<BigType> sv;
33     assert(sv.data()->buffer[0] == 10);
34     assert(sv.size() == 1);
35   }
36   {
37     const std::ranges::single_view<BigType> sv;
38     assert(sv.data()->buffer[0] == 10);
39     assert(sv.size() == 1);
40   }
41 
42   return true;
43 }
44 
45 int main(int, char**) {
46   test();
47   static_assert(test());
48 
49   return 0;
50 }
51