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 | // constexpr mapping(const extents_type&) noexcept; |
14 | // |
15 | // Preconditions: The size of the multidimensional index space e is representable |
16 | // as a value of type index_type ([basic.fundamental]). |
17 | // |
18 | // Effects: Direct-non-list-initializes extents_ with e. |
19 | |
20 | #include <mdspan> |
21 | #include <cassert> |
22 | #include <cstdint> |
23 | |
24 | #include "test_macros.h" |
25 | |
26 | template <class E> |
27 | constexpr void test_construction(E e) { |
28 | using M = std::layout_right::mapping<E>; |
29 | ASSERT_NOEXCEPT(M{e}); |
30 | M m(e); |
31 | |
32 | // check correct extents are returned |
33 | ASSERT_NOEXCEPT(m.extents()); |
34 | assert(m.extents() == e); |
35 | |
36 | // check required_span_size() |
37 | typename E::index_type expected_size = 1; |
38 | for (typename E::rank_type r = 0; r < E::rank(); r++) |
39 | expected_size *= e.extent(r); |
40 | assert(m.required_span_size() == expected_size); |
41 | } |
42 | |
43 | constexpr bool test() { |
44 | constexpr size_t D = std::dynamic_extent; |
45 | test_construction(std::extents<int>()); |
46 | test_construction(std::extents<unsigned, D>(7)); |
47 | test_construction(std::extents<unsigned, 7>()); |
48 | test_construction(std::extents<unsigned, 7, 8>()); |
49 | test_construction(std::extents<int64_t, D, 8, D, D>(7, 9, 10)); |
50 | return true; |
51 | } |
52 | |
53 | int main(int, char**) { |
54 | test(); |
55 | static_assert(test()); |
56 | return 0; |
57 | } |
58 | |