Debian Codegraph @

libcxx/test/std/containers/views/mdspan/layout_left/ctor.default.pass.cpp

raw
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 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10
11 // <mdspan>
12
13 // Test default construction:
14 //
15 // constexpr mapping() noexcept = default;
16
17 #include <mdspan>
18 #include <cassert>
19 #include <cstdint>
20
21 #include "test_macros.h"
22
23 template <class E>
24 constexpr void test_construction() {
25 using M = std::layout_left::mapping<E>;
26 ASSERT_NOEXCEPT(M{});
27 M m;
28 E e;
29
30 // check correct extents are returned
31 ASSERT_NOEXCEPT(m.extents());
32 assert(m.extents() == e);
33
34 // check required_span_size()
35 typename E::index_type expected_size = 1;
36 for (typename E::rank_type r = 0; r < E::rank(); r++)
37 expected_size *= e.extent(r);
38 assert(m.required_span_size() == expected_size);
39 }
40
41 constexpr bool test() {
42 constexpr size_t D = std::dynamic_extent;
43 test_construction<std::extents<int>>();
44 test_construction<std::extents<unsigned, D>>();
45 test_construction<std::extents<unsigned, 7>>();
46 test_construction<std::extents<unsigned, 7, 8>>();
47 test_construction<std::extents<int64_t, D, 8, D, D>>();
48 return true;
49 }
50
51 int main(int, char**) {
52 test();
53 static_assert(test());
54 return 0;
55 }