| 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 <mdspan> |
| 20 |
#include <cassert> |
| 21 |
#include <type_traits> |
| 22 |
|
| 23 |
#include "../ConvertibleToIntegral.h" |
| 24 |
#include "test_macros.h" |
| 25 |
|
| 26 |
struct NoDefaultCtorIndex { |
| 27 |
size_t value; |
| 28 |
constexpr NoDefaultCtorIndex() = delete; |
| 29 |
constexpr NoDefaultCtorIndex(size_t val) : value(val) {} |
| 30 |
constexpr operator size_t() const noexcept { return value; } |
| 31 |
}; |
| 32 |
|
| 33 |
template <class E, class Expected> |
| 34 |
constexpr void test(E e, Expected expected) { |
| 35 |
ASSERT_SAME_TYPE(E, Expected); |
| 36 |
assert(e == expected); |
| 37 |
} |
| 38 |
|
| 39 |
constexpr bool test() { |
| 40 |
constexpr std::size_t D = std::dynamic_extent; |
| 41 |
|
| 42 |
test(std::extents(), std::extents<size_t>()); |
| 43 |
test(std::extents(1), std::extents<std::size_t, D>(1)); |
| 44 |
test(std::extents(1, 2u), std::extents<std::size_t, D, D>(1, 2u)); |
| 45 |
test(std::extents(1, 2u, 3, 4, 5, 6, 7, 8, 9), |
| 46 |
std::extents<std::size_t, D, D, D, D, D, D, D, D, D>(1, 2u, 3, 4, 5, 6, 7, 8, 9)); |
| 47 |
test(std::extents(NoDefaultCtorIndex{1}, NoDefaultCtorIndex{2}), std::extents<std::size_t, D, D>(1, 2)); |
| 48 |
|
| 49 |
#if _LIBCPP_STD_VER >= 26 |
| 50 |
// P3029R1: deduction from `integral_constant` |
| 51 |
test(std::extents(std::integral_constant<size_t, 5>{}), std::extents<std::size_t, 5>()); |
| 52 |
test(std::extents(std::integral_constant<size_t, 5>{}, 6), std::extents<std::size_t, 5, std::dynamic_extent>(6)); |
| 53 |
test(std::extents(std::integral_constant<size_t, 5>{}, 6, std::integral_constant<size_t, 7>{}), |
| 54 |
std::extents<std::size_t, 5, std::dynamic_extent, 7>(6)); |
| 55 |
#endif |
| 56 |
|
| 57 |
return true; |
| 58 |
} |
| 59 |
|
| 60 |
int main(int, char**) { |
| 61 |
test(); |
| 62 |
static_assert(test()); |
| 63 |
|
| 64 |
return 0; |
| 65 |
} |