xref: /freebsd-src/contrib/llvm-project/libcxx/include/__memory/allocate_at_least.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
181ad6265SDimitry Andric //===----------------------------------------------------------------------===//
281ad6265SDimitry Andric //
381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric //
781ad6265SDimitry Andric //===----------------------------------------------------------------------===//
881ad6265SDimitry Andric 
981ad6265SDimitry Andric #ifndef _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H
1081ad6265SDimitry Andric #define _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H
1181ad6265SDimitry Andric 
1281ad6265SDimitry Andric #include <__config>
1381ad6265SDimitry Andric #include <__memory/allocator_traits.h>
1481ad6265SDimitry Andric #include <cstddef>
1581ad6265SDimitry Andric 
1681ad6265SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1781ad6265SDimitry Andric #  pragma GCC system_header
1881ad6265SDimitry Andric #endif
1981ad6265SDimitry Andric 
2081ad6265SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
2181ad6265SDimitry Andric 
2206c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 23
2381ad6265SDimitry Andric 
2481ad6265SDimitry Andric template <class _Alloc>
25cb14a3feSDimitry Andric [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto __allocate_at_least(_Alloc& __alloc, size_t __n) {
26*0fca6ea1SDimitry Andric   return std::allocator_traits<_Alloc>::allocate_at_least(__alloc, __n);
2781ad6265SDimitry Andric }
28*0fca6ea1SDimitry Andric 
2981ad6265SDimitry Andric #else
30*0fca6ea1SDimitry Andric 
3181ad6265SDimitry Andric template <class _Pointer>
3281ad6265SDimitry Andric struct __allocation_result {
3381ad6265SDimitry Andric   _Pointer ptr;
3481ad6265SDimitry Andric   size_t count;
3581ad6265SDimitry Andric };
3681ad6265SDimitry Andric 
3781ad6265SDimitry Andric template <class _Alloc>
38*0fca6ea1SDimitry Andric _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI
39*0fca6ea1SDimitry Andric _LIBCPP_CONSTEXPR __allocation_result<typename allocator_traits<_Alloc>::pointer>
40cb14a3feSDimitry Andric __allocate_at_least(_Alloc& __alloc, size_t __n) {
4181ad6265SDimitry Andric   return {__alloc.allocate(__n), __n};
4281ad6265SDimitry Andric }
4381ad6265SDimitry Andric 
4406c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 23
4581ad6265SDimitry Andric 
4681ad6265SDimitry Andric _LIBCPP_END_NAMESPACE_STD
4781ad6265SDimitry Andric 
4881ad6265SDimitry Andric #endif // _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H
49