[libcxx-commits] [mlir] [llvm] [clang] [libc] [libcxx] [flang] [libc++][memory] P1132R8: out_ptr - a scalable output pointer abstraction (PR #73618)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Dec 14 08:31:14 PST 2023


================
@@ -0,0 +1,102 @@
+// -*- 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___INOUT_PTR_H
+#define _LIBCPP___INOUT_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_same.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 _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");
+
+public:
+  _LIBCPP_HIDE_FROM_ABI explicit inout_ptr_t(_Smart& __s, _Args... __args)
+      : __s_(__s), __a_(std::forward<_Args>(__args)...), __p_([&__s] {
+          if constexpr (is_pointer_v<_Smart>) {
+            return __s;
+          } else {
+            return __s.get();
+          }
+        }()) {
+    if constexpr (requires { __s.release(); }) {
+      __s.release();
+    } else {
+      __s = _Smart();
+    }
+  }
+
+  _LIBCPP_HIDE_FROM_ABI inout_ptr_t(const inout_ptr_t&) = delete;
+
+  _LIBCPP_HIDE_FROM_ABI ~inout_ptr_t() {
+    if constexpr (!is_pointer_v<_Smart>) {
----------------
ldionne wrote:

Does this `if constexpr` have a test?

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


More information about the libcxx-commits mailing list