brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 4d8cffb Raw
72 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <array>10 11// reference front();  // constexpr in C++1712// reference back();   // constexpr in C++1713 14#include <array>15#include <cassert>16 17#include "test_macros.h"18 19TEST_CONSTEXPR_CXX17 bool tests() {20  {21    typedef double T;22    typedef std::array<T, 3> C;23    C c = {1, 2, 3.5};24 25    C::reference r1 = c.front();26    assert(r1 == 1);27    r1 = 5.5;28    assert(c[0] == 5.5);29 30    C::reference r2 = c.back();31    assert(r2 == 3.5);32    r2 = 7.5;33    assert(c[2] == 7.5);34  }35  {36    typedef double T;37    typedef std::array<T, 0> C;38    C c = {};39    ASSERT_SAME_TYPE(decltype(c.back()), C::reference);40    LIBCPP_ASSERT_NOEXCEPT(c.back());41    ASSERT_SAME_TYPE(decltype(c.front()), C::reference);42    LIBCPP_ASSERT_NOEXCEPT(c.front());43    if (c.size() > (0)) { // always false44      TEST_IGNORE_NODISCARD c.front();45      TEST_IGNORE_NODISCARD c.back();46    }47  }48  {49    typedef double T;50    typedef std::array<const T, 0> C;51    C c = {};52    ASSERT_SAME_TYPE(decltype(c.back()), C::reference);53    LIBCPP_ASSERT_NOEXCEPT(c.back());54    ASSERT_SAME_TYPE(decltype(c.front()), C::reference);55    LIBCPP_ASSERT_NOEXCEPT(c.front());56    if (c.size() > (0)) {57      TEST_IGNORE_NODISCARD c.front();58      TEST_IGNORE_NODISCARD c.back();59    }60  }61 62  return true;63}64 65int main(int, char**) {66  tests();67#if TEST_STD_VER >= 1768  static_assert(tests(), "");69#endif70  return 0;71}72