[clang][OpenMP] OpenMP 6.0 updates to restrictions with order/concurrent (#125621)
[llvm-project.git] / libcxx / test / std / containers / views / mdspan / layout_stride / ctor.default.pass.cpp
blob055986d80c7263c445b334f3b29569f427e3dd96
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
11 // <mdspan>
13 // Test default construction:
15 // constexpr mapping() noexcept;
18 // Preconditions: layout_right::mapping<extents_type>().required_span_size() is representable as a value of type index_type ([basic.fundamental]).
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).
23 #include <cassert>
24 #include <cstddef>
25 #include <cstdint>
26 #include <mdspan>
27 #include <span> // dynamic_extent
29 #include "test_macros.h"
31 template <class E>
32 constexpr void test_construction() {
33 using M = std::layout_stride::mapping<E>;
34 ASSERT_NOEXCEPT(M{});
35 M m;
36 E e;
38 // check correct extents are returned
39 ASSERT_NOEXCEPT(m.extents());
40 assert(m.extents() == e);
42 // check required_span_size()
43 typename E::index_type expected_size = 1;
44 for (typename E::rank_type r = 0; r < E::rank(); r++)
45 expected_size *= e.extent(r);
46 assert(m.required_span_size() == expected_size);
48 // check strides: node stride function is constrained on rank>0, e.extent(r) is not
49 auto strides = m.strides();
50 ASSERT_NOEXCEPT(m.strides());
51 if constexpr (E::rank() > 0) {
52 std::layout_right::mapping<E> m_right;
53 for (typename E::rank_type r = 0; r < E::rank(); r++) {
54 assert(m.stride(r) == m_right.stride(r));
55 assert(strides[r] == m.stride(r));
60 constexpr bool test() {
61 constexpr size_t D = std::dynamic_extent;
62 test_construction<std::extents<int>>();
63 test_construction<std::extents<unsigned, D>>();
64 test_construction<std::extents<unsigned, 7>>();
65 test_construction<std::extents<unsigned, 0>>();
66 test_construction<std::extents<unsigned, 7, 8>>();
67 test_construction<std::extents<int64_t, D, 8, D, D>>();
68 return true;
71 int main(int, char**) {
72 test();
73 static_assert(test());
74 return 0;