1c5c29006SMarshall Clow //===----------------------------------------------------------------------===//
2c5c29006SMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6c5c29006SMarshall Clow //
7c5c29006SMarshall Clow //===----------------------------------------------------------------------===//
8c5c29006SMarshall Clow
9c5c29006SMarshall Clow // <array>
10c5c29006SMarshall Clow
11c5c29006SMarshall Clow // An array is a contiguous container
12c5c29006SMarshall Clow
13c5c29006SMarshall Clow #include <array>
14c5c29006SMarshall Clow #include <cassert>
15c5c29006SMarshall Clow
167fc6a556SMarshall Clow #include "test_macros.h"
177fc6a556SMarshall Clow
18*77b9abfcSLouis Dionne template <class Container>
assert_contiguous(Container const & c)19*77b9abfcSLouis Dionne TEST_CONSTEXPR_CXX14 void assert_contiguous(Container const& c)
20c5c29006SMarshall Clow {
21c5c29006SMarshall Clow for (size_t i = 0; i < c.size(); ++i)
22c5c29006SMarshall Clow assert(*(c.begin() + i) == *(std::addressof(*c.begin()) + i));
23c5c29006SMarshall Clow }
24c5c29006SMarshall Clow
tests()25*77b9abfcSLouis Dionne TEST_CONSTEXPR_CXX17 bool tests()
26c5c29006SMarshall Clow {
27*77b9abfcSLouis Dionne assert_contiguous(std::array<double, 0>());
28*77b9abfcSLouis Dionne assert_contiguous(std::array<double, 1>());
29*77b9abfcSLouis Dionne assert_contiguous(std::array<double, 2>());
30*77b9abfcSLouis Dionne assert_contiguous(std::array<double, 3>());
31*77b9abfcSLouis Dionne
32*77b9abfcSLouis Dionne assert_contiguous(std::array<char, 0>());
33*77b9abfcSLouis Dionne assert_contiguous(std::array<char, 1>());
34*77b9abfcSLouis Dionne assert_contiguous(std::array<char, 2>());
35*77b9abfcSLouis Dionne assert_contiguous(std::array<char, 3>());
36*77b9abfcSLouis Dionne
37*77b9abfcSLouis Dionne return true;
38c5c29006SMarshall Clow }
392df59c50SJF Bastien
main(int,char **)40*77b9abfcSLouis Dionne int main(int, char**)
41*77b9abfcSLouis Dionne {
42*77b9abfcSLouis Dionne tests();
43*77b9abfcSLouis Dionne #if TEST_STD_VER >= 17 // begin() & friends are constexpr in >= C++17 only
44*77b9abfcSLouis Dionne static_assert(tests(), "");
45*77b9abfcSLouis Dionne #endif
462df59c50SJF Bastien return 0;
47c5c29006SMarshall Clow }
48