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 // constexpr index_type stride(rank_type i) const noexcept; 14cfa096d9SChristian Trott // 15cfa096d9SChristian Trott // Constraints: extents_type::rank() > 0 is true. 16cfa096d9SChristian Trott // 17cfa096d9SChristian Trott // Preconditions: i < extents_type::rank() is true. 18cfa096d9SChristian Trott // 19cfa096d9SChristian Trott // Returns: extents().rev-prod-of-extents(i). 20cfa096d9SChristian Trott 21cfa096d9SChristian Trott #include <mdspan> 22cfa096d9SChristian Trott #include <array> 23*5e19fd17SLouis Dionne #include <cassert> 24cfa096d9SChristian Trott #include <cstdint> 25cfa096d9SChristian Trott #include <cstdio> 26*5e19fd17SLouis Dionne #include <span> // dynamic_extent 27*5e19fd17SLouis Dionne 28cfa096d9SChristian Trott #include "test_macros.h" 29cfa096d9SChristian Trott 30cfa096d9SChristian Trott template <class E, class... Args> 31cfa096d9SChristian Trott constexpr void test_stride(std::array<typename E::index_type, E::rank()> strides, Args... args) { 32cfa096d9SChristian Trott using M = std::layout_right::mapping<E>; 33cfa096d9SChristian Trott M m(E(args...)); 34cfa096d9SChristian Trott 35cfa096d9SChristian Trott ASSERT_NOEXCEPT(m.stride(0)); 36cfa096d9SChristian Trott for (size_t r = 0; r < E::rank(); r++) 37cfa096d9SChristian Trott assert(strides[r] == m.stride(r)); 38cfa096d9SChristian Trott } 39cfa096d9SChristian Trott 40cfa096d9SChristian Trott constexpr bool test() { 41cfa096d9SChristian Trott constexpr size_t D = std::dynamic_extent; 42cfa096d9SChristian Trott test_stride<std::extents<unsigned, D>>(std::array<unsigned, 1>{1}, 7); 43cfa096d9SChristian Trott test_stride<std::extents<unsigned, 7>>(std::array<unsigned, 1>{1}); 44cfa096d9SChristian Trott test_stride<std::extents<unsigned, 7, 8>>(std::array<unsigned, 2>{8, 1}); 45cfa096d9SChristian Trott test_stride<std::extents<int64_t, D, 8, D, D>>(std::array<int64_t, 4>{720, 90, 10, 1}, 7, 9, 10); 46cfa096d9SChristian Trott return true; 47cfa096d9SChristian Trott } 48cfa096d9SChristian Trott 49cfa096d9SChristian Trott int main(int, char**) { 50cfa096d9SChristian Trott test(); 51cfa096d9SChristian Trott static_assert(test()); 52cfa096d9SChristian Trott return 0; 53cfa096d9SChristian Trott } 54