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 mapping(const extents_type&) noexcept;
14//
15// Preconditions: The size of the multidimensional index space e is representable
16// as a value of type index_type ([basic.fundamental]).
17//
18// Effects: Direct-non-list-initializes extents_ with e.
19
20#include <cassert>
21#include <cstddef>
22#include <cstdint>
23#include <mdspan>
24
25#include "test_macros.h"
26
27template <class E>
28constexpr void test_construction(E e) {
29 using M = std::layout_left::mapping<E>;
30 ASSERT_NOEXCEPT(M{e});
31 M m(e);
32
33 // check correct extents are returned
34 ASSERT_NOEXCEPT(m.extents());
35 assert(m.extents() == e);
36
37 // check required_span_size()
38 typename E::index_type expected_size = 1;
39 for (typename E::rank_type r = 0; r < E::rank(); r++)
40 expected_size *= e.extent(r);
41 assert(m.required_span_size() == expected_size);
42}
43
44constexpr bool test() {
45 constexpr size_t D = std::dynamic_extent;
46 test_construction(std::extents<int>());
47 test_construction(std::extents<unsigned, D>(7));
48 test_construction(std::extents<unsigned, 7>());
49 test_construction(std::extents<unsigned, 7, 8>());
50 test_construction(std::extents<int64_t, D, 8, D, D>(7, 9, 10));
51 return true;
52}
53
54int main(int, char**) {
55 test();
56 static_assert(test());
57 return 0;
58}
59

source code of libcxx/test/std/containers/views/mdspan/layout_left/ctor.extents.pass.cpp