brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · d795223 Raw
67 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// const_reference front() const; // constexpr in C++1412// const_reference back() const;  // constexpr in C++1413 14#include <array>15#include <cassert>16 17#include "test_macros.h"18 19TEST_CONSTEXPR_CXX14 bool tests() {20  {21    typedef double T;22    typedef std::array<T, 3> C;23    C const c             = {1, 2, 3.5};24    C::const_reference r1 = c.front();25    assert(r1 == 1);26 27    C::const_reference r2 = c.back();28    assert(r2 == 3.5);29  }30  {31    typedef double T;32    typedef std::array<T, 0> C;33    C const c = {};34    ASSERT_SAME_TYPE(decltype(c.back()), C::const_reference);35    LIBCPP_ASSERT_NOEXCEPT(c.back());36    ASSERT_SAME_TYPE(decltype(c.front()), C::const_reference);37    LIBCPP_ASSERT_NOEXCEPT(c.front());38    if (c.size() > (0)) { // always false39      TEST_IGNORE_NODISCARD c.front();40      TEST_IGNORE_NODISCARD c.back();41    }42  }43  {44    typedef double T;45    typedef std::array<const T, 0> C;46    C const c = {};47    ASSERT_SAME_TYPE(decltype(c.back()), C::const_reference);48    LIBCPP_ASSERT_NOEXCEPT(c.back());49    ASSERT_SAME_TYPE(decltype(c.front()), C::const_reference);50    LIBCPP_ASSERT_NOEXCEPT(c.front());51    if (c.size() > (0)) {52      TEST_IGNORE_NODISCARD c.front();53      TEST_IGNORE_NODISCARD c.back();54    }55  }56 57  return true;58}59 60int main(int, char**) {61  tests();62#if TEST_STD_VER >= 1463  static_assert(tests(), "");64#endif65  return 0;66}67