#include <mdspan>
#include <type_traits>
#include <concepts>
#include <cassert>
#include "test_macros.h"
template <class E>
constexpr void
test_layout_mapping_stride(E ext, std::array<typename E::index_type, E::rank()> strides, bool exhaustive) {
using M = std::layout_stride::mapping<E>;
M m(ext, strides);
const M c_m = m;
assert(m.strides() == strides);
assert(c_m.strides() == strides);
assert(m.extents() == ext);
assert(c_m.extents() == ext);
assert(M::is_unique() == true);
assert(m.is_exhaustive() == exhaustive);
assert(c_m.is_exhaustive() == exhaustive);
assert(M::is_strided() == true);
assert(M::is_always_unique() == true);
assert(M::is_always_exhaustive() == false);
assert(M::is_always_strided() == true);
ASSERT_NOEXCEPT(m.strides());
ASSERT_NOEXCEPT(c_m.strides());
ASSERT_NOEXCEPT(m.extents());
ASSERT_NOEXCEPT(c_m.extents());
ASSERT_NOEXCEPT(M::is_unique());
ASSERT_NOEXCEPT(m.is_exhaustive());
ASSERT_NOEXCEPT(c_m.is_exhaustive());
ASSERT_NOEXCEPT(M::is_strided());
ASSERT_NOEXCEPT(M::is_always_unique());
ASSERT_NOEXCEPT(M::is_always_exhaustive());
ASSERT_NOEXCEPT(M::is_always_strided());
for (typename E::rank_type r = 0; r < E::rank(); r++) {
assert(m.stride(r) == strides[r]);
assert(c_m.stride(r) == strides[r]);
ASSERT_NOEXCEPT(m.stride(r));
ASSERT_NOEXCEPT(c_m.stride(r));
}
typename E::index_type expected_size = 1;
for (typename E::rank_type r = 0; r < E::rank(); r++) {
if (ext.extent(r) == 0) {
expected_size = 0;
break;
}
expected_size += (ext.extent(r) - 1) * static_cast<typename E::index_type>(strides[r]);
}
assert(m.required_span_size() == expected_size);
assert(c_m.required_span_size() == expected_size);
ASSERT_NOEXCEPT(m.required_span_size());
ASSERT_NOEXCEPT(c_m.required_span_size());
static_assert(std::is_trivially_copyable_v<M>);
static_assert(std::regular<M>);
}
constexpr bool test() {
constexpr size_t D = std::dynamic_extent;
test_layout_mapping_stride(std::extents<int>(), std::array<int, 0>{}, true);
test_layout_mapping_stride(std::extents<signed char, 4, 5>(), std::array<signed char, 2>{1, 4}, true);
test_layout_mapping_stride(std::extents<signed char, 4, 5>(), std::array<signed char, 2>{1, 5}, false);
test_layout_mapping_stride(std::extents<unsigned, D, 4>(7), std::array<unsigned, 2>{20, 2}, false);
test_layout_mapping_stride(std::extents<size_t, D, D, D, D>(3, 3, 3, 3), std::array<size_t, 4>{3, 1, 9, 27}, true);
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}