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 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
9 | |
10 | // <mdspan> |
11 | |
12 | // template <class... Integrals> |
13 | // explicit extents(Integrals...) -> see below; |
14 | // Constraints: (is_convertible_v<Integrals, size_t> && ...) is true. |
15 | // |
16 | // Remarks: The deduced type is dextents<size_t, sizeof...(Integrals)>. // until C++26 |
17 | // Remarks: The deduced type is extents<size_t, maybe-static-ext<Integrals>...>. // since C++26 |
18 | |
19 | #include <cassert> |
20 | #include <cstddef> |
21 | #include <mdspan> |
22 | #include <type_traits> |
23 | |
24 | #include "../ConvertibleToIntegral.h" |
25 | #include "test_macros.h" |
26 | |
27 | struct NoDefaultCtorIndex { |
28 | size_t value; |
29 | constexpr NoDefaultCtorIndex() = delete; |
30 | constexpr NoDefaultCtorIndex(size_t val) : value(val) {} |
31 | constexpr operator size_t() const noexcept { return value; } |
32 | }; |
33 | |
34 | template <class E, class Expected> |
35 | constexpr void test(E e, Expected expected) { |
36 | ASSERT_SAME_TYPE(E, Expected); |
37 | assert(e == expected); |
38 | } |
39 | |
40 | constexpr bool test() { |
41 | constexpr std::size_t D = std::dynamic_extent; |
42 | |
43 | test(std::extents(), std::extents<size_t>()); |
44 | test(std::extents(1), std::extents<std::size_t, D>(1)); |
45 | test(std::extents(1, 2u), std::extents<std::size_t, D, D>(1, 2u)); |
46 | test(std::extents(1, 2u, 3, 4, 5, 6, 7, 8, 9), |
47 | std::extents<std::size_t, D, D, D, D, D, D, D, D, D>(1, 2u, 3, 4, 5, 6, 7, 8, 9)); |
48 | test(std::extents(NoDefaultCtorIndex{1}, NoDefaultCtorIndex{2}), std::extents<std::size_t, D, D>(1, 2)); |
49 | |
50 | #if _LIBCPP_STD_VER >= 26 |
51 | // P3029R1: deduction from `integral_constant` |
52 | test(std::extents(std::integral_constant<size_t, 5>{}), std::extents<std::size_t, 5>()); |
53 | test(std::extents(std::integral_constant<size_t, 5>{}, 6), std::extents<std::size_t, 5, std::dynamic_extent>(6)); |
54 | test(std::extents(std::integral_constant<size_t, 5>{}, 6, std::integral_constant<size_t, 7>{}), |
55 | std::extents<std::size_t, 5, std::dynamic_extent, 7>(6)); |
56 | #endif |
57 | |
58 | return true; |
59 | } |
60 | |
61 | int main(int, char**) { |
62 | test(); |
63 | static_assert(test()); |
64 | |
65 | return 0; |
66 | } |
67 | |