[libcxx-commits] [libcxx] [libc++][memory] P1132R8: `out_ptr` - a scalable output pointer abstraction (PR #73618)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 17 08:00:07 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* >);
----------------
ldionne wrote:
Here and below, we can't use libc++ private helpers cause the test suite needs to work with other implementations as well. I would either remove this `static_assert` or turn it into `LIBCPP_STATIC_ASSERT` if it's really really important to check.
https://github.com/llvm/llvm-project/pull/73618
More information about the libcxx-commits
mailing list