[libcxx-commits] [libcxx] [libc++] Implement P2897R7 aligned_accessor: An mdspan accessor expressing pointer over-alignment (PR #122603)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jan 31 13:13:44 PST 2025
================
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, c++23
+
+// <mdspan>
+//
+// template<class OtherElementType>
+// explicit constexpr aligned_accessor(
+// default_accessor<OtherElementType>) noexcept {}
+//
+// Constraints: is_convertible_v<OtherElementType(*)[], element_type(*)[]> is true.
+
+#include <mdspan>
+#include <cassert>
+#include <cstdint>
+#include <type_traits>
+
+#include "test_macros.h"
+
+#include "../MinimalElementType.h"
+
+struct Base {};
+struct Derived : public Base {};
+
+template <class FromT, class ToT, size_t ToN>
+constexpr void test_conversion() {
+ std::default_accessor<FromT> from;
+ ASSERT_NOEXCEPT(std::aligned_accessor<ToT, ToN>(from));
+ [[maybe_unused]] std::aligned_accessor<ToT, ToN> to(from);
+ // check that the constructor is explicit
+ static_assert(std::is_nothrow_constructible_v<std::aligned_accessor<ToT, ToN>, std::default_accessor<ToT>>);
+ static_assert(!std::is_convertible_v<std::default_accessor<ToT>, std::aligned_accessor<ToT, ToN>>);
+}
+
+template <class From, class To>
+constexpr void test_it() {
+ constexpr size_t N = alignof(To);
----------------
ldionne wrote:
```suggestion
constexpr std::size_t N = alignof(To);
```
https://github.com/llvm/llvm-project/pull/122603
More information about the libcxx-commits
mailing list