| 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 |
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 9 |
|
| 10 |
// <mdspan> |
| 11 |
|
| 12 |
// Test default construction: |
| 13 |
// |
| 14 |
// constexpr extents() noexcept = default; |
| 15 |
// |
| 16 |
// Remarks: since the standard uses an exposition only array member, dynamic extents |
| 17 |
// need to be zero initialized! |
| 18 |
|
| 19 |
#include <mdspan> |
| 20 |
#include <cassert> |
| 21 |
#include <array> |
| 22 |
|
| 23 |
#include "../ConvertibleToIntegral.h" |
| 24 |
#include "CtorTestCombinations.h" |
| 25 |
#include "test_macros.h" |
| 26 |
|
| 27 |
struct DefaultCtorTest { |
| 28 |
template <class E, class AllExtents, class Extents, size_t... Indices> |
| 29 |
static constexpr void test_construction(AllExtents all_ext, Extents, std::index_sequence<Indices...>) { |
| 30 |
// This function gets called twice: once with Extents being just the dynamic ones, and once with all the extents specified. |
| 31 |
// We only test during the all extent case, since then Indices is the correct number. This allows us to reuse the same |
| 32 |
// testing machinery used in other constructor tests. |
| 33 |
if constexpr (sizeof...(Indices) == E::rank()) { |
| 34 |
ASSERT_NOEXCEPT(E{}); |
| 35 |
// Need to construct new expected values, replacing dynamic values with 0 |
| 36 |
std::array<typename AllExtents::value_type, E::rank()> expected_exts{ |
| 37 |
((E::static_extent(Indices) == std::dynamic_extent) |
| 38 |
? typename AllExtents::value_type(0) |
| 39 |
: all_ext[Indices])...}; |
| 40 |
test_runtime_observers(E{}, expected_exts); |
| 41 |
} |
| 42 |
} |
| 43 |
}; |
| 44 |
|
| 45 |
int main(int, char**) { |
| 46 |
test_index_type_combo<DefaultCtorTest>(); |
| 47 |
static_assert(test_index_type_combo<DefaultCtorTest>()); |
| 48 |
return 0; |
| 49 |
} |