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