This commit implements layout_left in support of C++23 mdspan (https://wg21.link/p0009). layout_left is a layout mapping policy whose index mapping corresponds to the memory layout of Fortran arrays. Thus the left most index has stride-1 access, and the right most index is associated with the largest stride. Co-authored-by: Damien L-G <dalg24@gmail.com> Differential Revision: https://reviews.llvm.org/D153783
67 lines
2.1 KiB
C++
67 lines
2.1 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
|
|
|
|
// <mdspan>
|
|
|
|
// namespace std {
|
|
// template<class Extents>
|
|
// class layout_left::mapping {
|
|
//
|
|
// ...
|
|
// static constexpr bool is_always_unique() noexcept { return true; }
|
|
// static constexpr bool is_always_exhaustive() noexcept { return true; }
|
|
// static constexpr bool is_always_strided() noexcept { return true; }
|
|
//
|
|
// static constexpr bool is_unique() noexcept { return true; }
|
|
// static constexpr bool is_exhaustive() noexcept { return true; }
|
|
// static constexpr bool is_strided() noexcept { return true; }
|
|
// ...
|
|
// };
|
|
// }
|
|
|
|
#include <mdspan>
|
|
#include <type_traits>
|
|
#include <concepts>
|
|
#include <cassert>
|
|
|
|
#include "test_macros.h"
|
|
|
|
template <class E>
|
|
constexpr void test_layout_mapping_left() {
|
|
using M = std::layout_left::template mapping<E>;
|
|
assert(M::is_unique() == true);
|
|
assert(M::is_exhaustive() == true);
|
|
assert(M::is_strided() == true);
|
|
assert(M::is_always_unique() == true);
|
|
assert(M::is_always_exhaustive() == true);
|
|
assert(M::is_always_strided() == true);
|
|
ASSERT_NOEXCEPT(std::declval<M>().is_unique());
|
|
ASSERT_NOEXCEPT(std::declval<M>().is_exhaustive());
|
|
ASSERT_NOEXCEPT(std::declval<M>().is_strided());
|
|
ASSERT_NOEXCEPT(M::is_always_unique());
|
|
ASSERT_NOEXCEPT(M::is_always_exhaustive());
|
|
ASSERT_NOEXCEPT(M::is_always_strided());
|
|
}
|
|
|
|
constexpr bool test() {
|
|
constexpr size_t D = std::dynamic_extent;
|
|
test_layout_mapping_left<std::extents<int>>();
|
|
test_layout_mapping_left<std::extents<char, 4, 5>>();
|
|
test_layout_mapping_left<std::extents<unsigned, D, 4>>();
|
|
test_layout_mapping_left<std::extents<size_t, D, D, D, D>>();
|
|
return true;
|
|
}
|
|
|
|
int main(int, char**) {
|
|
test();
|
|
static_assert(test());
|
|
return 0;
|
|
}
|