[libcxx-commits] [libcxx] [libc++] Partially implement P2642R6: Padded mdspan layouts (PR #187873)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Mar 21 11:16:27 PDT 2026


================
@@ -0,0 +1,86 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <mdspan>
+
+// template<class LayoutRightPaddedMapping>
+// constexpr mapping(const LayoutRightPaddedMapping& other);
+
+#include <cassert>
+#include <cstddef>
+#include <mdspan>
+#include <type_traits>
+
+template <class Dst, class Src>
+constexpr void assert_same_mapping(const Dst& dst, const Src& src) {
+  assert(dst.extents() == src.extents());
+
+  if constexpr (Dst::extents_type::rank() > 0) {
+    for (typename Dst::rank_type r = 0; r < Dst::extents_type::rank(); ++r)
+      assert(dst.stride(r) == static_cast<typename Dst::index_type>(src.stride(r)));
+  }
+}
+
+template <bool Implicit, class Dst, class Src>
+constexpr void test_conversion(const Src& source) {
+  static_assert(std::is_constructible_v<Dst, Src>);
+
+  Dst direct(source);
+  assert_same_mapping(direct, source);
+
+  if constexpr (Implicit) {
+    Dst implicit = source;
+    assert_same_mapping(implicit, source);
+  } else {
+    static_assert(!std::is_convertible_v<Src, Dst>);
+  }
+}
+
+constexpr bool test() {
+  constexpr size_t D = std::dynamic_extent;
+
+#if 0 // TODO
+  {
+    using Src = std::layout_right_padded<4>::mapping<std::extents<size_t, 4, 7>>;
+    using Dst = std::layout_right_padded<4>::mapping<std::extents<size_t, D, 7>>;
+    Src source;
+    test_conversion<true, Dst>(source);
+  }
+#endif
----------------
eiytoq wrote:

Same as above.

https://github.com/llvm/llvm-project/pull/187873


More information about the libcxx-commits mailing list