2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___MEMORY_TEMPORARY_BUFFER_H
11 #define _LIBCPP___MEMORY_TEMPORARY_BUFFER_H
14 #include <__cstddef/ptrdiff_t.h>
15 #include <__memory/unique_temporary_buffer.h>
16 #include <__utility/pair.h>
18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19 # pragma GCC system_header
22 #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER)
24 _LIBCPP_BEGIN_NAMESPACE_STD
27 [[__nodiscard__
]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17 pair
<_Tp
*, ptrdiff_t>
28 get_temporary_buffer(ptrdiff_t __n
) _NOEXCEPT
{
29 __unique_temporary_buffer
<_Tp
> __unique_buf
= std::__allocate_unique_temporary_buffer
<_Tp
>(__n
);
30 pair
<_Tp
*, ptrdiff_t> __result(__unique_buf
.get(), __unique_buf
.get_deleter().__count_
);
31 __unique_buf
.release();
36 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17
void return_temporary_buffer(_Tp
* __p
) _NOEXCEPT
{
37 __unique_temporary_buffer
<_Tp
> __unique_buf(__p
);
41 _LIBCPP_END_NAMESPACE_STD
43 #endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER)
45 #endif // _LIBCPP___MEMORY_TEMPORARY_BUFFER_H