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