brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 72140d0 Raw
54 lines · c
1//===----------------------------------------------------------------------===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H10#define _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H11 12#include <__config>13#include <__cstddef/size_t.h>14#include <__memory/allocator_traits.h>15 16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17#  pragma GCC system_header18#endif19 20_LIBCPP_BEGIN_NAMESPACE_STD21 22template <class _Pointer, class _SizeT = size_t>23struct __allocation_result {24  _Pointer ptr;25  _SizeT count;26 27  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __allocation_result(_Pointer __ptr, _SizeT __count)28      : ptr(__ptr), count(__count) {}29};30_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(__allocation_result);31 32#if _LIBCPP_STD_VER >= 2333 34template <class _Alloc>35[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto __allocate_at_least(_Alloc& __alloc, size_t __n) {36  auto __res = std::allocator_traits<_Alloc>::allocate_at_least(__alloc, __n);37  return __allocation_result{__res.ptr, __res.count};38}39 40#else41 42template <class _Alloc, class _Traits = allocator_traits<_Alloc> >43[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI44_LIBCPP_CONSTEXPR __allocation_result<typename _Traits::pointer, typename _Traits::size_type>45__allocate_at_least(_Alloc& __alloc, size_t __n) {46  return __allocation_result<typename _Traits::pointer, typename _Traits::size_type>(__alloc.allocate(__n), __n);47}48 49#endif // _LIBCPP_STD_VER >= 2350 51_LIBCPP_END_NAMESPACE_STD52 53#endif // _LIBCPP___MEMORY_ALLOCATE_AT_LEAST_H54