xref: /llvm-project/libcxx/test/std/containers/views/mdspan/layout_right/properties.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 // namespace std {
14cfa096d9SChristian Trott //   template<class Extents>
15cfa096d9SChristian Trott //   class layout_right::mapping {
16cfa096d9SChristian Trott //
17cfa096d9SChristian Trott //     ...
18cfa096d9SChristian Trott //     static constexpr bool is_always_unique() noexcept { return true; }
19cfa096d9SChristian Trott //     static constexpr bool is_always_exhaustive() noexcept { return true; }
20cfa096d9SChristian Trott //     static constexpr bool is_always_strided() noexcept { return true; }
21cfa096d9SChristian Trott //
22cfa096d9SChristian Trott //     static constexpr bool is_unique() noexcept { return true; }
23cfa096d9SChristian Trott //     static constexpr bool is_exhaustive() noexcept { return true; }
24cfa096d9SChristian Trott //     static constexpr bool is_strided() noexcept { return true; }
25cfa096d9SChristian Trott //     ...
26cfa096d9SChristian Trott //   };
27cfa096d9SChristian Trott // }
28cfa096d9SChristian Trott 
29cfa096d9SChristian Trott #include <cassert>
30*e99c4906SNikolas Klauser #include <cstddef>
31*e99c4906SNikolas Klauser #include <mdspan>
325e19fd17SLouis Dionne #include <span> // dynamic_extent
3309e3a360SLouis Dionne #include <utility>
34cfa096d9SChristian Trott 
35cfa096d9SChristian Trott #include "test_macros.h"
36cfa096d9SChristian Trott 
37cfa096d9SChristian Trott template <class E>
38cfa096d9SChristian Trott constexpr void test_layout_mapping_right() {
3902d513cfSStephan T. Lavavej   using M = std::layout_right::mapping<E>;
40cfa096d9SChristian Trott   assert(M::is_unique() == true);
41cfa096d9SChristian Trott   assert(M::is_exhaustive() == true);
42cfa096d9SChristian Trott   assert(M::is_strided() == true);
43cfa096d9SChristian Trott   assert(M::is_always_unique() == true);
44cfa096d9SChristian Trott   assert(M::is_always_exhaustive() == true);
45cfa096d9SChristian Trott   assert(M::is_always_strided() == true);
46cfa096d9SChristian Trott   ASSERT_NOEXCEPT(std::declval<M>().is_unique());
47cfa096d9SChristian Trott   ASSERT_NOEXCEPT(std::declval<M>().is_exhaustive());
48cfa096d9SChristian Trott   ASSERT_NOEXCEPT(std::declval<M>().is_strided());
49cfa096d9SChristian Trott   ASSERT_NOEXCEPT(M::is_always_unique());
50cfa096d9SChristian Trott   ASSERT_NOEXCEPT(M::is_always_exhaustive());
51cfa096d9SChristian Trott   ASSERT_NOEXCEPT(M::is_always_strided());
52cfa096d9SChristian Trott }
53cfa096d9SChristian Trott 
54cfa096d9SChristian Trott constexpr bool test() {
55cfa096d9SChristian Trott   constexpr size_t D = std::dynamic_extent;
56cfa096d9SChristian Trott   test_layout_mapping_right<std::extents<int>>();
57ab562686SStephan T. Lavavej   test_layout_mapping_right<std::extents<signed char, 4, 5>>();
58cfa096d9SChristian Trott   test_layout_mapping_right<std::extents<unsigned, D, 4>>();
59cfa096d9SChristian Trott   test_layout_mapping_right<std::extents<size_t, D, D, D, D>>();
60cfa096d9SChristian Trott   return true;
61cfa096d9SChristian Trott }
62cfa096d9SChristian Trott 
63cfa096d9SChristian Trott int main(int, char**) {
64cfa096d9SChristian Trott   test();
65cfa096d9SChristian Trott   static_assert(test());
66cfa096d9SChristian Trott   return 0;
67cfa096d9SChristian Trott }
68