1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 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 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef _LIBCPP___MEMORY_TEMPORARY_BUFFER_H 11 #define _LIBCPP___MEMORY_TEMPORARY_BUFFER_H 12 13 #include <__config> 14 #include <__cstddef/ptrdiff_t.h> 15 #include <__memory/unique_temporary_buffer.h> 16 #include <__utility/pair.h> 17 18 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 19 # pragma GCC system_header 20 #endif 21 22 #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER) 23 24 _LIBCPP_BEGIN_NAMESPACE_STD 25 26 template <class _Tp> 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(); 32 return __result; 33 } 34 35 template <class _Tp> 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); 38 (void)__unique_buf; 39 } 40 41 _LIBCPP_END_NAMESPACE_STD 42 43 #endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_TEMPORARY_BUFFER) 44 45 #endif // _LIBCPP___MEMORY_TEMPORARY_BUFFER_H 46