[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / array / front_back.pass.cpp
blob18985e90a89e1ace122734d358f4f56ebb8563f8
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 //===----------------------------------------------------------------------===//
9 // <array>
11 // reference front(); // constexpr in C++17
12 // reference back(); // constexpr in C++17
14 #include <array>
15 #include <cassert>
17 #include "test_macros.h"
19 // std::array is explicitly allowed to be initialized with A a = { init-list };.
20 // Disable the missing braces warning for this reason.
21 #include "disable_missing_braces_warning.h"
24 TEST_CONSTEXPR_CXX17 bool tests()
27 typedef double T;
28 typedef std::array<T, 3> C;
29 C c = {1, 2, 3.5};
31 C::reference r1 = c.front();
32 assert(r1 == 1);
33 r1 = 5.5;
34 assert(c[0] == 5.5);
36 C::reference r2 = c.back();
37 assert(r2 == 3.5);
38 r2 = 7.5;
39 assert(c[2] == 7.5);
42 typedef double T;
43 typedef std::array<T, 0> C;
44 C c = {};
45 ASSERT_SAME_TYPE(decltype(c.back()), C::reference);
46 LIBCPP_ASSERT_NOEXCEPT(c.back());
47 ASSERT_SAME_TYPE(decltype(c.front()), C::reference);
48 LIBCPP_ASSERT_NOEXCEPT(c.front());
49 if (c.size() > (0)) { // always false
50 TEST_IGNORE_NODISCARD c.front();
51 TEST_IGNORE_NODISCARD c.back();
55 typedef double T;
56 typedef std::array<const T, 0> C;
57 C c = {};
58 ASSERT_SAME_TYPE(decltype( c.back()), C::reference);
59 LIBCPP_ASSERT_NOEXCEPT( c.back());
60 ASSERT_SAME_TYPE(decltype( c.front()), C::reference);
61 LIBCPP_ASSERT_NOEXCEPT( c.front());
62 if (c.size() > (0)) {
63 TEST_IGNORE_NODISCARD c.front();
64 TEST_IGNORE_NODISCARD c.back();
68 return true;
71 int main(int, char**)
73 tests();
74 #if TEST_STD_VER >= 17
75 static_assert(tests(), "");
76 #endif
77 return 0;