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 // constexpr T* data() noexcept;
13 // constexpr const T* data() const noexcept;
14
15 #include <ranges>
16 #include <cassert>
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 auto sv = std::ranges::single_view<int>(42);
26 assert(*sv.data() == 42);
27
28 ASSERT_SAME_TYPE(decltype(sv.data()), int*);
29 static_assert(noexcept(sv.data()));
30 }
31 {
32 const auto sv = std::ranges::single_view<int>(42);
33 assert(*sv.data() == 42);
34
35 ASSERT_SAME_TYPE(decltype(sv.data()), const int*);
36 static_assert(noexcept(sv.data()));
37 }
38
39 {
40 auto sv = std::ranges::single_view<Empty>(Empty());
41 assert(sv.data() != nullptr);
42
43 ASSERT_SAME_TYPE(decltype(sv.data()), Empty*);
44 }
45 {
46 const auto sv = std::ranges::single_view<Empty>(Empty());
47 assert(sv.data() != nullptr);
48
49 ASSERT_SAME_TYPE(decltype(sv.data()), const Empty*);
50 }
51
52 {
53 auto sv = std::ranges::single_view<BigType>(BigType());
54 assert(sv.data()->buffer[0] == 10);
55
56 ASSERT_SAME_TYPE(decltype(sv.data()), BigType*);
57 }
58 {
59 const auto sv = std::ranges::single_view<BigType>(BigType());
60 assert(sv.data()->buffer[0] == 10);
61
62 ASSERT_SAME_TYPE(decltype(sv.data()), const BigType*);
63 }
64
65 return true;
66 }
67
main(int,char **)68 int main(int, char**) {
69 test();
70 static_assert(test());
71
72 return 0;
73 }
74