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