[SLP] Make getSameOpcode support different instructions if they have same semantics...
[llvm-project.git] / libcxx / test / std / containers / sequences / array / front_back.pass.cpp
blobc37acd0b786381c36afec71eb5aa904c0bc395f6
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 TEST_CONSTEXPR_CXX17 bool tests()
22 typedef double T;
23 typedef std::array<T, 3> C;
24 C c = {1, 2, 3.5};
26 C::reference r1 = c.front();
27 assert(r1 == 1);
28 r1 = 5.5;
29 assert(c[0] == 5.5);
31 C::reference r2 = c.back();
32 assert(r2 == 3.5);
33 r2 = 7.5;
34 assert(c[2] == 7.5);
37 typedef double T;
38 typedef std::array<T, 0> C;
39 C c = {};
40 ASSERT_SAME_TYPE(decltype(c.back()), C::reference);
41 LIBCPP_ASSERT_NOEXCEPT(c.back());
42 ASSERT_SAME_TYPE(decltype(c.front()), C::reference);
43 LIBCPP_ASSERT_NOEXCEPT(c.front());
44 if (c.size() > (0)) { // always false
45 TEST_IGNORE_NODISCARD c.front();
46 TEST_IGNORE_NODISCARD c.back();
50 typedef double T;
51 typedef std::array<const T, 0> C;
52 C c = {};
53 ASSERT_SAME_TYPE(decltype( c.back()), C::reference);
54 LIBCPP_ASSERT_NOEXCEPT( c.back());
55 ASSERT_SAME_TYPE(decltype( c.front()), C::reference);
56 LIBCPP_ASSERT_NOEXCEPT( c.front());
57 if (c.size() > (0)) {
58 TEST_IGNORE_NODISCARD c.front();
59 TEST_IGNORE_NODISCARD c.back();
63 return true;
66 int main(int, char**)
68 tests();
69 #if TEST_STD_VER >= 17
70 static_assert(tests(), "");
71 #endif
72 return 0;