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