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 // template<class T>
14 // class empty_view;
15 
16 #include <ranges>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 template<class T>
22 constexpr void testType() {
23   static_assert(std::ranges::range<std::ranges::empty_view<T>>);
24   static_assert(std::ranges::range<const std::ranges::empty_view<T>>);
25   static_assert(std::ranges::view<std::ranges::empty_view<T>>);
26 
27   std::ranges::empty_view<T> empty;
28 
29   assert(empty.begin() == nullptr);
30   assert(empty.end() == nullptr);
31   assert(empty.data() == nullptr);
32   assert(empty.size() == 0);
33   assert(empty.empty() == true);
34 
35   assert(std::ranges::begin(empty) == nullptr);
36   assert(std::ranges::end(empty) == nullptr);
37   assert(std::ranges::data(empty) == nullptr);
38   assert(std::ranges::size(empty) == 0);
39   assert(std::ranges::empty(empty) == true);
40 }
41 
42 struct Empty {};
43 struct BigType { char buff[8]; };
44 
45 template<class T>
46 concept ValidEmptyView = requires { typename std::ranges::empty_view<T>; };
47 
48 constexpr bool test() {
49   // Not objects:
50   static_assert(!ValidEmptyView<int&>);
51   static_assert(!ValidEmptyView<void>);
52 
53   testType<int>();
54   testType<const int>();
55   testType<int*>();
56   testType<Empty>();
57   testType<const Empty>();
58   testType<BigType>();
59 
60   return true;
61 }
62 
63 int main(int, char**) {
64   test();
65   static_assert(test());
66 
67   return 0;
68 }
69