1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
13 // Test default construction:
15 // constexpr mapping() noexcept;
18 // Preconditions: layout_right::mapping<extents_type>().required_span_size() is representable as a value of type index_type ([basic.fundamental]).
20 // Effects: Direct-non-list-initializes extents_ with extents_type(), and for all d in the range [0, rank_),
21 // direct-non-list-initializes strides_[d] with layout_right::mapping<extents_type>().stride(d).
27 #include <span> // dynamic_extent
29 #include "test_macros.h"
32 constexpr void test_construction() {
33 using M
= std::layout_stride::mapping
<E
>;
38 // check correct extents are returned
39 ASSERT_NOEXCEPT(m
.extents());
40 assert(m
.extents() == e
);
42 // check required_span_size()
43 typename
E::index_type expected_size
= 1;
44 for (typename
E::rank_type r
= 0; r
< E::rank(); r
++)
45 expected_size
*= e
.extent(r
);
46 assert(m
.required_span_size() == expected_size
);
48 // check strides: node stride function is constrained on rank>0, e.extent(r) is not
49 auto strides
= m
.strides();
50 ASSERT_NOEXCEPT(m
.strides());
51 if constexpr (E::rank() > 0) {
52 std::layout_right::mapping
<E
> m_right
;
53 for (typename
E::rank_type r
= 0; r
< E::rank(); r
++) {
54 assert(m
.stride(r
) == m_right
.stride(r
));
55 assert(strides
[r
] == m
.stride(r
));
60 constexpr bool test() {
61 constexpr size_t D
= std::dynamic_extent
;
62 test_construction
<std::extents
<int>>();
63 test_construction
<std::extents
<unsigned, D
>>();
64 test_construction
<std::extents
<unsigned, 7>>();
65 test_construction
<std::extents
<unsigned, 0>>();
66 test_construction
<std::extents
<unsigned, 7, 8>>();
67 test_construction
<std::extents
<int64_t, D
, 8, D
, D
>>();
71 int main(int, char**) {
73 static_assert(test());