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