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 index_type required_span_size() const noexcept; |
14 | // |
15 | // Returns: extents().fwd-prod-of-extents(extents_type::rank()). |
16 | |
17 | |
18 | #include <mdspan> |
19 | #include <cassert> |
20 | #include <cstdint> |
21 | |
22 | #include "test_macros.h" |
23 | |
24 | template <class E> |
25 | constexpr void test_required_span_size(E e, typename E::index_type expected_size) { |
26 | using M = std::layout_right::mapping<E>; |
27 | const M m(e); |
28 | |
29 | ASSERT_NOEXCEPT(m.required_span_size()); |
30 | assert(m.required_span_size() == expected_size); |
31 | } |
32 | |
33 | constexpr bool test() { |
34 | constexpr size_t D = std::dynamic_extent; |
35 | test_required_span_size(std::extents<int>(), 1); |
36 | test_required_span_size(std::extents<unsigned, D>(0), 0); |
37 | test_required_span_size(std::extents<unsigned, D>(1), 1); |
38 | test_required_span_size(std::extents<unsigned, D>(7), 7); |
39 | test_required_span_size(std::extents<unsigned, 7>(), 7); |
40 | test_required_span_size(std::extents<unsigned, 7, 8>(), 56); |
41 | test_required_span_size(std::extents<int64_t, D, 8, D, D>(7, 9, 10), 5040); |
42 | test_required_span_size(std::extents<int64_t, 1, 8, D, D>(9, 10), 720); |
43 | test_required_span_size(std::extents<int64_t, 1, 0, D, D>(9, 10), 0); |
44 | return true; |
45 | } |
46 | |
47 | int main(int, char**) { |
48 | test(); |
49 | static_assert(test()); |
50 | return 0; |
51 | } |
52 | |