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// UNSUPPORTED: c++03, c++11, c++14, c++17
9
10// <span>
11
12// [[nodiscard]] constexpr bool empty() const noexcept;
13//
14
15#include <span>
16#include <cassert>
17#include <string>
18
19#include "test_macros.h"
20
21struct A {};
22constexpr int iArr1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
23int iArr2[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
24
25int main(int, char**) {
26 static_assert(noexcept(std::span<int>().empty()), "");
27 static_assert(noexcept(std::span<int, 0>().empty()), "");
28
29 static_assert(std::span<int>().empty(), "");
30 static_assert(std::span<long>().empty(), "");
31 static_assert(std::span<double>().empty(), "");
32 static_assert(std::span<A>().empty(), "");
33 static_assert(std::span<std::string>().empty(), "");
34
35 static_assert(std::span<int, 0>().empty(), "");
36 static_assert(std::span<long, 0>().empty(), "");
37 static_assert(std::span<double, 0>().empty(), "");
38 static_assert(std::span<A, 0>().empty(), "");
39 static_assert(std::span<std::string, 0>().empty(), "");
40
41 static_assert(!std::span<const int>(iArr1, 1).empty(), "");
42 static_assert(!std::span<const int>(iArr1, 2).empty(), "");
43 static_assert(!std::span<const int>(iArr1, 3).empty(), "");
44 static_assert(!std::span<const int>(iArr1, 4).empty(), "");
45 static_assert(!std::span<const int>(iArr1, 5).empty(), "");
46
47 assert((std::span<int>().empty()));
48 assert((std::span<long>().empty()));
49 assert((std::span<double>().empty()));
50 assert((std::span<A>().empty()));
51 assert((std::span<std::string>().empty()));
52
53 assert((std::span<int, 0>().empty()));
54 assert((std::span<long, 0>().empty()));
55 assert((std::span<double, 0>().empty()));
56 assert((std::span<A, 0>().empty()));
57 assert((std::span<std::string, 0>().empty()));
58
59 assert(!(std::span<int, 1>(iArr2, 1).empty()));
60 assert(!(std::span<int, 2>(iArr2, 2).empty()));
61 assert(!(std::span<int, 3>(iArr2, 3).empty()));
62 assert(!(std::span<int, 4>(iArr2, 4).empty()));
63 assert(!(std::span<int, 5>(iArr2, 5).empty()));
64
65 std::string s;
66 assert(((std::span<std::string>(&s, (std::size_t)0)).empty()));
67 assert(!((std::span<std::string>(&s, 1).empty())));
68
69 return 0;
70}
71

source code of libcxx/test/std/containers/views/views.span/span.obs/empty.pass.cpp