1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H
10 #define _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H
13 #include <__memory/allocator_traits.h>
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 # pragma GCC system_header
20 _LIBCPP_BEGIN_NAMESPACE_STD
22 #if _LIBCPP_STD_VER >= 23
23 template <class _Pointer
>
24 struct allocation_result
{
28 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(allocation_result
);
30 template <class _Alloc
>
31 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr
32 allocation_result
<typename allocator_traits
<_Alloc
>::pointer
> allocate_at_least(_Alloc
& __alloc
, size_t __n
) {
33 if constexpr (requires
{ __alloc
.allocate_at_least(__n
); }) {
34 return __alloc
.allocate_at_least(__n
);
36 return {__alloc
.allocate(__n
), __n
};
40 template <class _Alloc
>
41 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr
42 auto __allocate_at_least(_Alloc
& __alloc
, size_t __n
) {
43 return std::allocate_at_least(__alloc
, __n
);
46 template <class _Pointer
>
47 struct __allocation_result
{
52 template <class _Alloc
>
53 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
54 __allocation_result
<typename allocator_traits
<_Alloc
>::pointer
> __allocate_at_least(_Alloc
& __alloc
, size_t __n
) {
55 return {__alloc
.allocate(__n
), __n
};
58 #endif // _LIBCPP_STD_VER >= 23
60 _LIBCPP_END_NAMESPACE_STD
62 #endif // _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H