[libcxx-commits] [libcxx] [llvm] [libc++] Remove `get_temporary_buffer`/`return_temporary_buffer` (PR #100914)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Sep 1 04:33:29 PDT 2024
================
@@ -0,0 +1,89 @@
+// -*- 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___MEMORY_UNIQUE_TEMPORARY_BUFFER_H
+#define _LIBCPP___MEMORY_UNIQUE_TEMPORARY_BUFFER_H
+
+#include <__assert>
+#include <__config>
+
+#include <__memory/allocator.h>
+#include <__memory/unique_ptr.h>
+#include <__type_traits/is_constant_evaluated.h>
+#include <cstddef>
+#include <new>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Tp>
+struct __sized_temporary_buffer_deleter {
+ ptrdiff_t __count_; // ignored in non-constant evaluation
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __sized_temporary_buffer_deleter() _NOEXCEPT : __count_(0) {}
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __sized_temporary_buffer_deleter(ptrdiff_t __count) _NOEXCEPT
+ : __count_(__count) {}
+
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator()(_Tp* __ptr) _NOEXCEPT {
+ if (__libcpp_is_constant_evaluated()) {
+ allocator<_Tp>().deallocate(__ptr, __count_);
+ return;
+ }
+
+ std::__libcpp_deallocate_unsized((void*)__ptr, _LIBCPP_ALIGNOF(_Tp));
+ }
+};
+
+template <class _Tp>
+inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr<_Tp, __sized_temporary_buffer_deleter<_Tp> >
+__make_unique_sized_temporary_buffer(ptrdiff_t __count) {
+ typedef __sized_temporary_buffer_deleter<_Tp> __deleter_type;
+ typedef unique_ptr<_Tp, __deleter_type> __unique_buffer_type;
----------------
philnik777 wrote:
Let's use `using` declarations here instead of `typedef`s.
https://github.com/llvm/llvm-project/pull/100914
More information about the libcxx-commits
mailing list