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* end() noexcept;
13 // constexpr const T* end() 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.end() == sv.begin() + 1);
27 
28     ASSERT_SAME_TYPE(decltype(sv.end()), int*);
29     static_assert(noexcept(sv.end()));
30   }
31   {
32     const auto sv = std::ranges::single_view<int>(42);
33     assert(sv.end() == sv.begin() + 1);
34 
35     ASSERT_SAME_TYPE(decltype(sv.end()), const int*);
36     static_assert(noexcept(sv.end()));
37   }
38 
39   {
40     auto sv = std::ranges::single_view<Empty>(Empty());
41     assert(sv.end() == sv.begin() + 1);
42 
43     ASSERT_SAME_TYPE(decltype(sv.end()), Empty*);
44   }
45   {
46     const auto sv = std::ranges::single_view<Empty>(Empty());
47     assert(sv.end() == sv.begin() + 1);
48 
49     ASSERT_SAME_TYPE(decltype(sv.end()), const Empty*);
50   }
51 
52   {
53     auto sv = std::ranges::single_view<BigType>(BigType());
54     assert(sv.end() == sv.begin() + 1);
55 
56     ASSERT_SAME_TYPE(decltype(sv.end()), BigType*);
57   }
58   {
59     const auto sv = std::ranges::single_view<BigType>(BigType());
60     assert(sv.end() == sv.begin() + 1);
61 
62     ASSERT_SAME_TYPE(decltype(sv.end()), 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