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

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 17 08:06:32 PDT 2024


================
@@ -0,0 +1,84 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 TEST_LIBCXX_UTILITIES_SMARTPTR_ADAPT_TYPES_H
+#define TEST_LIBCXX_UTILITIES_SMARTPTR_ADAPT_TYPES_H
+
+#include <type_traits>
+#include <memory>
+
+// Custom deleters.
+
+template <typename T>
+struct MoveOnlyDeleter {
+  MoveOnlyDeleter()                                  = default;
+  MoveOnlyDeleter(const MoveOnlyDeleter&)            = delete;
+  MoveOnlyDeleter& operator=(const MoveOnlyDeleter&) = delete;
+  MoveOnlyDeleter(MoveOnlyDeleter&&) : wasMoveInitilized{true} {}
+  MoveOnlyDeleter& operator=(MoveOnlyDeleter&&) = default;
+
+  void operator()(T* p) const { delete p; }
+
+  bool wasMoveInitilized = false;
+};
+
+// Custom pointer types.
+
+template <typename T>
+struct ConstructiblePtr {
+  using pointer = T*;
+  std::unique_ptr<T> ptr;
+
+  ConstructiblePtr() = default;
+  explicit ConstructiblePtr(T* p) : ptr{p} {}
+
+  auto operator==(T val) { return *ptr == val; }
+
+  auto* get() const { return ptr.get(); }
+
+  void release() { ptr.release(); }
+};
+
+static_assert(std::is_same_v<std::__pointer_of_t< ConstructiblePtr<int>>, int* >);
----------------
H-G-Hristov wrote:

I think I'd like to have that test. I'll convert it to `LIBCPP_STATIC_ASSERT`. Thanks!

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


More information about the libcxx-commits mailing list