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 // constexpr explicit single_view(const T& t); 14 // constexpr explicit single_view(T&& t); 15 16 #include <cassert> 17 #include <ranges> 18 #include <utility> 19 20 #include "test_macros.h" 21 22 struct Empty {}; 23 struct BigType { char buffer[64] = {10}; }; 24 25 constexpr bool test() { 26 { 27 BigType bt; 28 std::ranges::single_view<BigType> sv(bt); 29 assert(sv.data()->buffer[0] == 10); 30 assert(sv.size() == 1); 31 } 32 { 33 const BigType bt; 34 const std::ranges::single_view<BigType> sv(bt); 35 assert(sv.data()->buffer[0] == 10); 36 assert(sv.size() == 1); 37 } 38 39 { 40 BigType bt; 41 std::ranges::single_view<BigType> sv(std::move(bt)); 42 assert(sv.data()->buffer[0] == 10); 43 assert(sv.size() == 1); 44 } 45 { 46 const BigType bt; 47 const std::ranges::single_view<BigType> sv(std::move(bt)); 48 assert(sv.data()->buffer[0] == 10); 49 assert(sv.size() == 1); 50 } 51 52 return true; 53 } 54 55 int main(int, char**) { 56 test(); 57 static_assert(test()); 58 59 return 0; 60 } 61