• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //===----------------------------------------------------------------------===//
8 
9 // <array>
10 
11 // GCC 5 doesn't implement the required constexpr support
12 // UNSUPPORTED: gcc-5
13 
14 // An array is a contiguous container
15 
16 #include <array>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 template <class Container>
assert_contiguous(Container const & c)22 TEST_CONSTEXPR_CXX14 void assert_contiguous(Container const& c)
23 {
24     for (size_t i = 0; i < c.size(); ++i)
25         assert(*(c.begin() + i) == *(std::addressof(*c.begin()) + i));
26 }
27 
tests()28 TEST_CONSTEXPR_CXX17 bool tests()
29 {
30     assert_contiguous(std::array<double, 0>());
31     assert_contiguous(std::array<double, 1>());
32     assert_contiguous(std::array<double, 2>());
33     assert_contiguous(std::array<double, 3>());
34 
35     assert_contiguous(std::array<char, 0>());
36     assert_contiguous(std::array<char, 1>());
37     assert_contiguous(std::array<char, 2>());
38     assert_contiguous(std::array<char, 3>());
39 
40     return true;
41 }
42 
main(int,char **)43 int main(int, char**)
44 {
45     tests();
46 #if TEST_STD_VER >= 17 // begin() & friends are constexpr in >= C++17 only
47     static_assert(tests(), "");
48 #endif
49     return 0;
50 }
51