xref: /llvm-project/libcxx/test/std/containers/views/mdspan/extents/ctor_default.pass.cpp (revision f5832bab6f5024cabe32a9f668b7f44e6b7cfef5)
1fcaccf81SChristian Trott //===----------------------------------------------------------------------===//
2fcaccf81SChristian Trott //
3fcaccf81SChristian Trott // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4fcaccf81SChristian Trott // See https://llvm.org/LICENSE.txt for license information.
5fcaccf81SChristian Trott // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6fcaccf81SChristian Trott //
7fcaccf81SChristian Trott //===----------------------------------------------------------------------===//
8fcaccf81SChristian Trott // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9fcaccf81SChristian Trott 
10fcaccf81SChristian Trott // <mdspan>
11fcaccf81SChristian Trott 
12fcaccf81SChristian Trott // Test default construction:
13fcaccf81SChristian Trott //
14fcaccf81SChristian Trott // constexpr extents() noexcept = default;
15fcaccf81SChristian Trott //
16fcaccf81SChristian Trott // Remarks: since the standard uses an exposition only array member, dynamic extents
17*f5832babSStephan T. Lavavej // need to be zero initialized!
18fcaccf81SChristian Trott 
19fcaccf81SChristian Trott #include <mdspan>
20fcaccf81SChristian Trott #include <cassert>
21fcaccf81SChristian Trott #include <array>
22fcaccf81SChristian Trott 
23cfa096d9SChristian Trott #include "../ConvertibleToIntegral.h"
24fcaccf81SChristian Trott #include "CtorTestCombinations.h"
25fcaccf81SChristian Trott #include "test_macros.h"
26fcaccf81SChristian Trott 
27fcaccf81SChristian Trott struct DefaultCtorTest {
28fcaccf81SChristian Trott   template <class E, class AllExtents, class Extents, size_t... Indices>
test_constructionDefaultCtorTest29fcaccf81SChristian Trott   static constexpr void test_construction(AllExtents all_ext, Extents, std::index_sequence<Indices...>) {
30fcaccf81SChristian Trott     // This function gets called twice: once with Extents being just the dynamic ones, and once with all the extents specified.
31fcaccf81SChristian Trott     // We only test during the all extent case, since then Indices is the correct number. This allows us to reuse the same
32fcaccf81SChristian Trott     // testing machinery used in other constructor tests.
33fcaccf81SChristian Trott     if constexpr (sizeof...(Indices) == E::rank()) {
34fcaccf81SChristian Trott       ASSERT_NOEXCEPT(E{});
35fcaccf81SChristian Trott       // Need to construct new expected values, replacing dynamic values with 0
36fcaccf81SChristian Trott       std::array<typename AllExtents::value_type, E::rank()> expected_exts{
37fcaccf81SChristian Trott           ((E::static_extent(Indices) == std::dynamic_extent)
38fcaccf81SChristian Trott                ? typename AllExtents::value_type(0)
39fcaccf81SChristian Trott                : all_ext[Indices])...};
40fcaccf81SChristian Trott       test_runtime_observers(E{}, expected_exts);
41fcaccf81SChristian Trott     }
42fcaccf81SChristian Trott   }
43fcaccf81SChristian Trott };
44fcaccf81SChristian Trott 
main(int,char **)45fcaccf81SChristian Trott int main(int, char**) {
46fcaccf81SChristian Trott   test_index_type_combo<DefaultCtorTest>();
47fcaccf81SChristian Trott   static_assert(test_index_type_combo<DefaultCtorTest>());
48fcaccf81SChristian Trott   return 0;
49fcaccf81SChristian Trott }
50