10Sstevel@tonic-gate//===----------------------------------------------------------------------===// 20Sstevel@tonic-gate// 30Sstevel@tonic-gate// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40Sstevel@tonic-gate// See https://llvm.org/LICENSE.txt for license information. 51618Srie// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 61618Srie// 70Sstevel@tonic-gate//===----------------------------------------------------------------------===// 80Sstevel@tonic-gate 90Sstevel@tonic-gate#ifndef _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H 100Sstevel@tonic-gate#define _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H 110Sstevel@tonic-gate 120Sstevel@tonic-gate#include <__config> 130Sstevel@tonic-gate#include <__memory/allocator_traits.h> 140Sstevel@tonic-gate#include <cstddef> 150Sstevel@tonic-gate 160Sstevel@tonic-gate#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 170Sstevel@tonic-gate# pragma GCC system_header 180Sstevel@tonic-gate#endif 190Sstevel@tonic-gate 200Sstevel@tonic-gate_LIBCPP_BEGIN_NAMESPACE_STD 211618Srie 220Sstevel@tonic-gate#if _LIBCPP_STD_VER > 20 234734Sab196087template <class _Pointer> 240Sstevel@tonic-gatestruct allocation_result { 250Sstevel@tonic-gate _Pointer ptr; 260Sstevel@tonic-gate size_t count; 270Sstevel@tonic-gate}; 280Sstevel@tonic-gate_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(allocation_result); 290Sstevel@tonic-gate 300Sstevel@tonic-gatetemplate <class _Alloc> 310Sstevel@tonic-gate[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr 320Sstevel@tonic-gateallocation_result<typename allocator_traits<_Alloc>::pointer> allocate_at_least(_Alloc& __alloc, size_t __n) { 330Sstevel@tonic-gate if constexpr (requires { __alloc.allocate_at_least(__n); }) { 340Sstevel@tonic-gate return __alloc.allocate_at_least(__n); 350Sstevel@tonic-gate } else { 360Sstevel@tonic-gate return {__alloc.allocate(__n), __n}; 370Sstevel@tonic-gate } 385088Sab196087} 395088Sab196087 400Sstevel@tonic-gatetemplate <class _Alloc> 411976Sab196087[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr 421976Sab196087auto __allocate_at_least(_Alloc& __alloc, size_t __n) { 434734Sab196087 return std::allocate_at_least(__alloc, __n); 440Sstevel@tonic-gate} 451976Sab196087#else 461976Sab196087template <class _Pointer> 471976Sab196087struct __allocation_result { 484734Sab196087 _Pointer ptr; 490Sstevel@tonic-gate size_t count; 501976Sab196087}; 514734Sab196087 521976Sab196087template <class _Alloc> 530Sstevel@tonic-gate_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR 541976Sab196087__allocation_result<typename allocator_traits<_Alloc>::pointer> __allocate_at_least(_Alloc& __alloc, size_t __n) { 554734Sab196087 return {__alloc.allocate(__n), __n}; 560Sstevel@tonic-gate} 574734Sab196087 584734Sab196087#endif // _LIBCPP_STD_VER > 20 594734Sab196087 604734Sab196087_LIBCPP_END_NAMESPACE_STD 614734Sab196087 624734Sab196087#endif // _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H 635088Sab196087