[flang-commits] [llvm] [libcxx] [mlir] [flang] [clang] [libc] [libc++][memory] P1132R8: out_ptr - a scalable output pointer abstraction (PR #73618)
Hristo Hristov via flang-commits
flang-commits at lists.llvm.org
Thu Dec 14 11:44:59 PST 2023
================
@@ -0,0 +1,97 @@
+// -*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___OUT_PTR_H
+#define _LIBCPP___OUT_PTR_H
+
+#include <__config>
+#include <__memory/addressof.h>
+#include <__memory/pointer_traits.h>
+#include <__memory/shared_ptr.h>
+#include <__memory/unique_ptr.h>
+#include <__type_traits/is_specialization.h>
+#include <__type_traits/is_void.h>
+#include <tuple>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+template <class _Tp>
+concept __resettable_adapted_ptr = requires(_Tp __ptr) { __ptr().reset(); };
+
+template <class _Smart, class _Pointer, class... _Args>
+class _LIBCPP_TEMPLATE_VIS out_ptr_t {
+ static_assert(!__is_specialization_v<_Smart, shared_ptr> || sizeof...(_Args) > 0,
+ "Specialization of std::shared_ptr<> requires a deleter.");
----------------
H-G-Hristov wrote:
@ldionne After rereading the specs I found this requirements, did we miss them?
![Screenshot 2023-12-14 at 21 20 25](https://github.com/llvm/llvm-project/assets/47526411/0965ebcc-0633-44a7-badc-5ac37eea97bc)
![Screenshot 2023-12-14 at 21 28 04](https://github.com/llvm/llvm-project/assets/47526411/76ad1bfc-a4e7-4ed9-9deb-37913f3f0d1b)
My interpretation is that the standard mandates:
```c++
template <class _Smart, class _Pointer, class... _Args>
class _LIBCPP_TEMPLATE_VIS out_ptr_t {
static_assert(!__is_specialization_v<_Smart, shared_ptr> || sizeof...(_Args) > 0,
"Specialization of std::shared_ptr<> requires a deleter.");
template <class _Smart, class _Pointer, class... _Args>
class _LIBCPP_TEMPLATE_VIS inout_ptr_t {
static_assert(!__is_specialization_v<_Smart, shared_ptr>, "std::shared_ptr<> is not supported");
```
Also implemented similarly in libstdc++ with more clear message than mine:
https://github.com/gcc-mirror/gcc/blob/95b70545331764c85079a1d0e1e19b605bda1456/libstdc%2B%2B-v3/include/bits/out_ptr.h#L57
https://github.com/gcc-mirror/gcc/blob/95b70545331764c85079a1d0e1e19b605bda1456/libstdc%2B%2B-v3/include/bits/out_ptr.h#L296
https://github.com/llvm/llvm-project/pull/73618
More information about the flang-commits
mailing list