brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · fda0f9e Raw
46 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// An array is a contiguous container12 13#include <array>14#include <cassert>15#include <memory>16 17#include "test_macros.h"18 19template <class Container>20TEST_CONSTEXPR_CXX14 void assert_contiguous(Container const& c) {21  for (std::size_t i = 0; i < c.size(); ++i)22    assert(*(c.begin() + i) == *(std::addressof(*c.begin()) + i));23}24 25TEST_CONSTEXPR_CXX17 bool tests() {26  assert_contiguous(std::array<double, 0>());27  assert_contiguous(std::array<double, 1>());28  assert_contiguous(std::array<double, 2>());29  assert_contiguous(std::array<double, 3>());30 31  assert_contiguous(std::array<char, 0>());32  assert_contiguous(std::array<char, 1>());33  assert_contiguous(std::array<char, 2>());34  assert_contiguous(std::array<char, 3>());35 36  return true;37}38 39int main(int, char**) {40  tests();41#if TEST_STD_VER >= 17 // begin() & friends are constexpr in >= C++17 only42  static_assert(tests(), "");43#endif44  return 0;45}46