File indexing completed on 2026-05-03 08:13:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___CXX03___MEMORY_TEMPORARY_BUFFER_H
0011 #define _LIBCPP___CXX03___MEMORY_TEMPORARY_BUFFER_H
0012
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__utility/pair.h>
0015 #include <__cxx03/cstddef>
0016 #include <__cxx03/new>
0017
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 # pragma GCC system_header
0020 #endif
0021
0022 _LIBCPP_BEGIN_NAMESPACE_STD
0023
0024 template <class _Tp>
0025 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_CFI _LIBCPP_DEPRECATED_IN_CXX17 pair<_Tp*, ptrdiff_t>
0026 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT {
0027 pair<_Tp*, ptrdiff_t> __r(0, 0);
0028 const ptrdiff_t __m =
0029 (~ptrdiff_t(0) ^ ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1))) / sizeof(_Tp);
0030 if (__n > __m)
0031 __n = __m;
0032 while (__n > 0) {
0033 #if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
0034 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) {
0035 align_val_t __al = align_val_t(_LIBCPP_ALIGNOF(_Tp));
0036 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), __al, nothrow));
0037 } else {
0038 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
0039 }
0040 #else
0041 if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp))) {
0042
0043
0044 return __r;
0045 }
0046
0047 __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
0048 #endif
0049
0050 if (__r.first) {
0051 __r.second = __n;
0052 break;
0053 }
0054 __n /= 2;
0055 }
0056 return __r;
0057 }
0058
0059 template <class _Tp>
0060 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_DEPRECATED_IN_CXX17 void return_temporary_buffer(_Tp* __p) _NOEXCEPT {
0061 std::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
0062 }
0063
0064 struct __return_temporary_buffer {
0065 _LIBCPP_SUPPRESS_DEPRECATED_PUSH
0066 template <class _Tp>
0067 _LIBCPP_HIDE_FROM_ABI void operator()(_Tp* __p) const {
0068 std::return_temporary_buffer(__p);
0069 }
0070 _LIBCPP_SUPPRESS_DEPRECATED_POP
0071 };
0072
0073 _LIBCPP_END_NAMESPACE_STD
0074
0075 #endif