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

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