[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / views / span.elem / front.pass.cpp
blob85c300aba1a9dc5b9b1598d7c2cd010a94a7b6fb
1 // -*- C++ -*-
2 //===------------------------------ span ---------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===---------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // <span>
13 // constexpr reference front() const noexcept;
14 // Expects: empty() is false.
15 // Effects: Equivalent to: return *data();
19 #include <span>
20 #include <cassert>
21 #include <string>
23 #include "test_macros.h"
26 template <typename Span>
27 constexpr bool testConstexprSpan(Span sp)
29 LIBCPP_ASSERT(noexcept(sp.front()));
30 return std::addressof(sp.front()) == sp.data();
34 template <typename Span>
35 void testRuntimeSpan(Span sp)
37 LIBCPP_ASSERT(noexcept(sp.front()));
38 assert(std::addressof(sp.front()) == sp.data());
41 template <typename Span>
42 void testEmptySpan(Span sp)
44 if (!sp.empty())
45 [[maybe_unused]] auto res = sp.front();
48 struct A{};
49 constexpr int iArr1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
50 int iArr2[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
52 int main(int, char**)
54 static_assert(testConstexprSpan(std::span<const int>(iArr1, 1)), "");
55 static_assert(testConstexprSpan(std::span<const int>(iArr1, 2)), "");
56 static_assert(testConstexprSpan(std::span<const int>(iArr1, 3)), "");
57 static_assert(testConstexprSpan(std::span<const int>(iArr1, 4)), "");
59 static_assert(testConstexprSpan(std::span<const int, 1>(iArr1, 1)), "");
60 static_assert(testConstexprSpan(std::span<const int, 2>(iArr1, 2)), "");
61 static_assert(testConstexprSpan(std::span<const int, 3>(iArr1, 3)), "");
62 static_assert(testConstexprSpan(std::span<const int, 4>(iArr1, 4)), "");
65 testRuntimeSpan(std::span<int>(iArr2, 1));
66 testRuntimeSpan(std::span<int>(iArr2, 2));
67 testRuntimeSpan(std::span<int>(iArr2, 3));
68 testRuntimeSpan(std::span<int>(iArr2, 4));
71 testRuntimeSpan(std::span<int, 1>(iArr2, 1));
72 testRuntimeSpan(std::span<int, 2>(iArr2, 2));
73 testRuntimeSpan(std::span<int, 3>(iArr2, 3));
74 testRuntimeSpan(std::span<int, 4>(iArr2, 4));
76 std::string s;
77 testRuntimeSpan(std::span<std::string> (&s, 1));
78 testRuntimeSpan(std::span<std::string, 1>(&s, 1));
80 std::span<int, 0> sp;
81 testEmptySpan(sp);
83 return 0;