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