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