Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions libcxx/include/__memory/allocate_at_least.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,31 @@

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _Pointer, class _SizeT = size_t>
struct __allocation_result {
_Pointer ptr;
_SizeT count;

_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __allocation_result(_Pointer __ptr, _SizeT __count)
: ptr(__ptr), count(__count) {}
};
_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__allocation_result);

#if _LIBCPP_STD_VER >= 23

template <class _Alloc>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto __allocate_at_least(_Alloc& __alloc, size_t __n) {
return std::allocator_traits<_Alloc>::allocate_at_least(__alloc, __n);
auto __res = std::allocator_traits<_Alloc>::allocate_at_least(__alloc, __n);
return __allocation_result{__res.ptr, __res.count};
}

#else

template <class _Pointer>
struct __allocation_result {
_Pointer ptr;
size_t count;
};

template <class _Alloc>
template <class _Alloc, class _Traits = allocator_traits<_Alloc> >
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI
_LIBCPP_CONSTEXPR __allocation_result<typename allocator_traits<_Alloc>::pointer>
_LIBCPP_CONSTEXPR __allocation_result<typename _Traits::pointer, typename _Traits::size_type>
__allocate_at_least(_Alloc& __alloc, size_t __n) {
return {__alloc.allocate(__n), __n};
return __allocation_result<typename _Traits::pointer, typename _Traits::size_type>(__alloc.allocate(__n), __n);
}

#endif // _LIBCPP_STD_VER >= 23
Expand Down
Loading
Loading