Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <array> |
| 10 | |
| 11 | // An array is a contiguous container |
| 12 | |
| 13 | #include <array> |
| 14 | #include <cassert> |
| 15 | |
Marshall Clow | 7fc6a55 | 2019-05-31 18:35:30 +0000 | [diff] [blame] | 16 | #include "test_macros.h" |
| 17 | |
Louis Dionne | 77b9abf | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 18 | template <class Container> |
| 19 | TEST_CONSTEXPR_CXX14 void assert_contiguous(Container const& c) |
Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 20 | { |
Louis Dionne | 77b9abf | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 21 | for (size_t i = 0; i < c.size(); ++i) |
| 22 | assert(*(c.begin() + i) == *(std::addressof(*c.begin()) + i)); |
| 23 | } |
| 24 | |
| 25 | TEST_CONSTEXPR_CXX17 bool tests() |
| 26 | { |
| 27 | assert_contiguous(std::array<double, 0>()); |
| 28 | assert_contiguous(std::array<double, 1>()); |
| 29 | assert_contiguous(std::array<double, 2>()); |
| 30 | assert_contiguous(std::array<double, 3>()); |
| 31 | |
| 32 | assert_contiguous(std::array<char, 0>()); |
| 33 | assert_contiguous(std::array<char, 1>()); |
| 34 | assert_contiguous(std::array<char, 2>()); |
| 35 | assert_contiguous(std::array<char, 3>()); |
| 36 | |
| 37 | return true; |
Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 38 | } |
| 39 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 40 | int main(int, char**) |
Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 41 | { |
Louis Dionne | 77b9abf | 2020-05-22 09:59:48 -0400 | [diff] [blame] | 42 | tests(); |
| 43 | #if TEST_STD_VER >= 17 // begin() & friends are constexpr in >= C++17 only |
| 44 | static_assert(tests(), ""); |
| 45 | #endif |
| 46 | return 0; |
Marshall Clow | c5c2900 | 2015-05-26 18:57:27 +0000 | [diff] [blame] | 47 | } |