Debian Codegraph @

libcxx/test/std/containers/views/mdspan/layout_stride/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;
16 //
17 //
18 // Preconditions: layout_right::mapping<extents_type>().required_span_size() is representable as a value of type index_type ([basic.fundamental]).
19 //
20 // Effects: Direct-non-list-initializes extents_ with extents_type(), and for all d in the range [0, rank_),
21 // direct-non-list-initializes strides_[d] with layout_right::mapping<extents_type>().stride(d).
22
23 #include <mdspan>
24 #include <cassert>
25 #include <cstdint>
26
27 #include "test_macros.h"
28
29 template <class E>
30 constexpr void test_construction() {
31 using M = std::layout_stride::mapping<E>;
32 ASSERT_NOEXCEPT(M{});
33 M m;
34 E e;
35
36 // check correct extents are returned
37 ASSERT_NOEXCEPT(m.extents());
38 assert(m.extents() == e);
39
40 // check required_span_size()
41 typename E::index_type expected_size = 1;
42 for (typename E::rank_type r = 0; r < E::rank(); r++)
43 expected_size *= e.extent(r);
44 assert(m.required_span_size() == expected_size);
45
46 // check strides: node stride function is constrained on rank>0, e.extent(r) is not
47 auto strides = m.strides();
48 ASSERT_NOEXCEPT(m.strides());
49 if constexpr (E::rank() > 0) {
50 std::layout_right::mapping<E> m_right;
51 for (typename E::rank_type r = 0; r < E::rank(); r++) {
52 assert(m.stride(r) == m_right.stride(r));
53 assert(strides[r] == m.stride(r));
54 }
55 }
56 }
57
58 constexpr bool test() {
59 constexpr size_t D = std::dynamic_extent;
60 test_construction<std::extents<int>>();
61 test_construction<std::extents<unsigned, D>>();
62 test_construction<std::extents<unsigned, 7>>();
63 test_construction<std::extents<unsigned, 0>>();
64 test_construction<std::extents<unsigned, 7, 8>>();
65 test_construction<std::extents<int64_t, D, 8, D, D>>();
66 return true;
67 }
68
69 int main(int, char**) {
70 test();
71 static_assert(test());
72 return 0;
73 }