[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / libcxx / test / std / containers / sequences / array / front_back.pass.cpp
blob5e0cb08ede077be63283ff43c8437e70af94fb0d
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
13 // const_reference front(); // constexpr in C++14
14 // const_reference back(); // constexpr in C++14
16 #include <array>
17 #include <cassert>
19 #include "test_macros.h"
21 // std::array is explicitly allowed to be initialized with A a = { init-list };.
22 // Disable the missing braces warning for this reason.
23 #include "disable_missing_braces_warning.h"
25 #if TEST_STD_VER > 14
26 constexpr bool check_front( double val )
28 std::array<double, 3> arr = {1, 2, 3.5};
29 return arr.front() == val;
32 constexpr bool check_back( double val )
34 std::array<double, 3> arr = {1, 2, 3.5};
35 return arr.back() == val;
37 #endif
39 int main(int, char**)
42 typedef double T;
43 typedef std::array<T, 3> C;
44 C c = {1, 2, 3.5};
46 C::reference r1 = c.front();
47 assert(r1 == 1);
48 r1 = 5.5;
49 assert(c[0] == 5.5);
51 C::reference r2 = c.back();
52 assert(r2 == 3.5);
53 r2 = 7.5;
54 assert(c[2] == 7.5);
57 typedef double T;
58 typedef std::array<T, 3> C;
59 const C c = {1, 2, 3.5};
60 C::const_reference r1 = c.front();
61 assert(r1 == 1);
63 C::const_reference r2 = c.back();
64 assert(r2 == 3.5);
67 typedef double T;
68 typedef std::array<T, 0> C;
69 C c = {};
70 C const& cc = c;
71 ASSERT_SAME_TYPE(decltype( c.back()), typename C::reference);
72 ASSERT_SAME_TYPE(decltype(cc.back()), typename C::const_reference);
73 LIBCPP_ASSERT_NOEXCEPT( c.back());
74 LIBCPP_ASSERT_NOEXCEPT( cc.back());
75 ASSERT_SAME_TYPE(decltype( c.front()), typename C::reference);
76 ASSERT_SAME_TYPE(decltype(cc.front()), typename C::const_reference);
77 LIBCPP_ASSERT_NOEXCEPT( c.front());
78 LIBCPP_ASSERT_NOEXCEPT( cc.front());
79 if (c.size() > (0)) { // always false
80 TEST_IGNORE_NODISCARD c.front();
81 TEST_IGNORE_NODISCARD c.back();
82 TEST_IGNORE_NODISCARD cc.front();
83 TEST_IGNORE_NODISCARD cc.back();
87 typedef double T;
88 typedef std::array<const T, 0> C;
89 C c = {{}};
90 C const& cc = c;
91 ASSERT_SAME_TYPE(decltype( c.back()), typename C::reference);
92 ASSERT_SAME_TYPE(decltype(cc.back()), typename C::const_reference);
93 LIBCPP_ASSERT_NOEXCEPT( c.back());
94 LIBCPP_ASSERT_NOEXCEPT( cc.back());
95 ASSERT_SAME_TYPE(decltype( c.front()), typename C::reference);
96 ASSERT_SAME_TYPE(decltype(cc.front()), typename C::const_reference);
97 LIBCPP_ASSERT_NOEXCEPT( c.front());
98 LIBCPP_ASSERT_NOEXCEPT( cc.front());
99 if (c.size() > (0)) {
100 TEST_IGNORE_NODISCARD c.front();
101 TEST_IGNORE_NODISCARD c.back();
102 TEST_IGNORE_NODISCARD cc.front();
103 TEST_IGNORE_NODISCARD cc.back();
106 #if TEST_STD_VER > 11
108 typedef double T;
109 typedef std::array<T, 3> C;
110 constexpr C c = {1, 2, 3.5};
112 constexpr T t1 = c.front();
113 static_assert (t1 == 1, "");
115 constexpr T t2 = c.back();
116 static_assert (t2 == 3.5, "");
118 #endif
120 #if TEST_STD_VER > 14
122 static_assert (check_front(1), "");
123 static_assert (check_back (3.5), "");
125 #endif
127 return 0;