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// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-ctad-maybe-unsupported
10
11// <mdspan>
12
13#include <mdspan>
14#include <type_traits>
15#include <concepts>
16#include <cassert>
17
18#include "test_macros.h"
19
20// mdspan
21
22// layout_stride::mapping does not have explicit deduction guides,
23// but implicit deduction guides for constructor taking extents and strides
24// should work
25
26constexpr bool test() {
27 constexpr size_t D = std::dynamic_extent;
28
29 ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents<int>(), std::array<unsigned, 0>())),
30 std::layout_stride::mapping<std::extents<int>>);
31 ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents<int, 4>(), std::array<char, 1>{1})),
32 std::layout_stride::mapping<std::extents<int, 4>>);
33 ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents<int, D>(), std::array<char, 1>{1})),
34 std::layout_stride::mapping<std::extents<int, D>>);
35 ASSERT_SAME_TYPE(
36 decltype(std::layout_stride::mapping(std::extents<unsigned, D, 3>(), std::array<int64_t, 2>{3, 100})),
37 std::layout_stride::mapping<std::extents<unsigned, D, 3>>);
38
39 ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents<int>(), std::span<unsigned, 0>())),
40 std::layout_stride::mapping<std::extents<int>>);
41 ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents<int, 4>(), std::declval<std::span<char, 1>>())),
42 std::layout_stride::mapping<std::extents<int, 4>>);
43 ASSERT_SAME_TYPE(decltype(std::layout_stride::mapping(std::extents<int, D>(), std::declval<std::span<char, 1>>())),
44 std::layout_stride::mapping<std::extents<int, D>>);
45 ASSERT_SAME_TYPE(
46 decltype(std::layout_stride::mapping(std::extents<unsigned, D, 3>(), std::declval<std::span<int64_t, 2>>())),
47 std::layout_stride::mapping<std::extents<unsigned, D, 3>>);
48 return true;
49}
50
51int main(int, char**) {
52 test();
53 static_assert(test());
54 return 0;
55}
56

source code of libcxx/test/std/containers/views/mdspan/layout_stride/deduction.pass.cpp