xref: /llvm-project/libcxx/test/std/containers/views/mdspan/layout_right/ctor.default.pass.cpp (revision e99c4906e44ae3f921fa05356909d006cda8d954)
1cfa096d9SChristian Trott //===----------------------------------------------------------------------===//
2cfa096d9SChristian Trott //
3cfa096d9SChristian Trott // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4cfa096d9SChristian Trott // See https://llvm.org/LICENSE.txt for license information.
5cfa096d9SChristian Trott // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6cfa096d9SChristian Trott //
7cfa096d9SChristian Trott //===----------------------------------------------------------------------===//
8cfa096d9SChristian Trott 
9cfa096d9SChristian Trott // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
10cfa096d9SChristian Trott 
11cfa096d9SChristian Trott // <mdspan>
12cfa096d9SChristian Trott 
13cfa096d9SChristian Trott // Test default construction:
14cfa096d9SChristian Trott //
15cfa096d9SChristian Trott // constexpr mapping() noexcept = default;
16cfa096d9SChristian Trott 
17cfa096d9SChristian Trott #include <cassert>
18*e99c4906SNikolas Klauser #include <cstddef>
19cfa096d9SChristian Trott #include <cstdint>
20*e99c4906SNikolas Klauser #include <mdspan>
215e19fd17SLouis Dionne #include <span> // dynamic_extent
22cfa096d9SChristian Trott 
23cfa096d9SChristian Trott #include "test_macros.h"
24cfa096d9SChristian Trott 
25cfa096d9SChristian Trott template <class E>
26cfa096d9SChristian Trott constexpr void test_construction() {
27cfa096d9SChristian Trott   using M = std::layout_right::mapping<E>;
28cfa096d9SChristian Trott   ASSERT_NOEXCEPT(M{});
29cfa096d9SChristian Trott   M m;
30cfa096d9SChristian Trott   E e;
31cfa096d9SChristian Trott 
32cfa096d9SChristian Trott   // check correct extents are returned
33cfa096d9SChristian Trott   ASSERT_NOEXCEPT(m.extents());
34cfa096d9SChristian Trott   assert(m.extents() == e);
35cfa096d9SChristian Trott 
36cfa096d9SChristian Trott   // check required_span_size()
37cfa096d9SChristian Trott   typename E::index_type expected_size = 1;
38cfa096d9SChristian Trott   for (typename E::rank_type r = 0; r < E::rank(); r++)
39cfa096d9SChristian Trott     expected_size *= e.extent(r);
40cfa096d9SChristian Trott   assert(m.required_span_size() == expected_size);
41cfa096d9SChristian Trott }
42cfa096d9SChristian Trott 
43cfa096d9SChristian Trott constexpr bool test() {
44cfa096d9SChristian Trott   constexpr size_t D = std::dynamic_extent;
45cfa096d9SChristian Trott   test_construction<std::extents<int>>();
46cfa096d9SChristian Trott   test_construction<std::extents<unsigned, D>>();
47cfa096d9SChristian Trott   test_construction<std::extents<unsigned, 7>>();
48cfa096d9SChristian Trott   test_construction<std::extents<unsigned, 7, 8>>();
49cfa096d9SChristian Trott   test_construction<std::extents<int64_t, D, 8, D, D>>();
50cfa096d9SChristian Trott   return true;
51cfa096d9SChristian Trott }
52cfa096d9SChristian Trott 
53cfa096d9SChristian Trott int main(int, char**) {
54cfa096d9SChristian Trott   test();
55cfa096d9SChristian Trott   static_assert(test());
56cfa096d9SChristian Trott   return 0;
57cfa096d9SChristian Trott }
58