23 #ifndef ABSL_MEMORY_MEMORY_H_ 24 #define ABSL_MEMORY_MEMORY_H_ 30 #include <type_traits> 74 return std::unique_ptr<T>(
ptr);
77 namespace memory_internal {
86 using array = std::unique_ptr<T[]>;
88 template <
typename T,
size_t N>
98 #if (__cplusplus > 201103L || defined(_MSC_VER)) && \ 99 !(defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 8) 165 template <
typename T,
typename... Args>
168 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
175 template <
typename T>
182 template <
typename T,
typename... Args>
184 Args&&... ) =
delete;
194 template <
typename T>
197 return (
ptr !=
nullptr) ? std::addressof(*
ptr) :
nullptr;
199 inline std::nullptr_t
RawPtr(std::nullptr_t) {
return nullptr; }
224 template <
typename T,
typename D>
226 return ptr ? std::shared_ptr<T>(
std::move(
ptr)) : std::shared_ptr<T>();
244 template <
typename T>
246 return std::weak_ptr<T>(
ptr);
249 namespace memory_internal {
252 template <
template <
typename>
class Extract,
typename Obj,
typename Default,
258 template <
template <
typename>
class Extract,
typename Obj,
typename Default>
263 template <
template <
typename>
class Extract,
typename Obj,
typename Default>
267 template <
typename T>
270 template <
typename T>
273 template <
typename T>
276 template <
typename T>
279 template <
typename T>
282 template <
typename T>
285 template <
typename T>
287 typename T::propagate_on_container_copy_assignment;
289 template <
typename T>
291 typename T::propagate_on_container_move_assignment;
293 template <
typename T>
296 template <
typename T>
299 template <
typename T>
302 template <
template <
typename...>
class Class,
typename T,
typename... Args>
307 template <
typename Ptr,
typename =
void>
312 template <
typename T>
314 using type =
typename T::element_type;
317 template <
typename T,
typename U>
320 template <
template <
typename...>
class Class,
typename T,
typename... Args,
323 using type = Class<U, Args...>;
326 template <
typename T,
typename U,
typename =
void>
331 template <
typename T,
typename U>
333 using type =
typename T::template rebind<U>;
336 template <
typename T,
typename U>
341 template <
typename T,
typename U>
346 template <
typename T,
typename U,
bool = HasRebindAlloc<T, U>(
nullptr)>
351 template <
typename T,
typename U>
353 using type =
typename T::template rebind<U>::other;
369 template <
typename Ptr>
387 template <
typename U>
393 return Ptr::pointer_to(r);
398 template <
typename T>
404 template <
typename U>
411 return std::addressof(r);
421 template <
typename Alloc>
440 template rebind<const value_type>>;
468 typename std::make_unsigned<difference_type>::type>;
488 Alloc, std::false_type>;
494 typename std::is_empty<Alloc>::type>;
499 template <
typename T>
504 template <
typename T>
511 return a.allocate(n);
519 return allocate_impl(0, a, n, hint);
533 template <
typename T,
typename... Args>
536 construct_impl(0, a, p, std::forward<Args>(args)...);
541 template <
typename T>
543 destroy_impl(0, a, p);
555 return select_on_container_copy_construction_impl(0, a);
559 template <
typename A>
562 -> decltype(
a.allocate(
n, hint)) {
563 return a.allocate(
n, hint);
567 return a.allocate(n);
570 template <
typename A,
typename... Args>
573 -> decltype(
a.construct(std::forward<Args>(args)...)) {
574 a.construct(std::forward<Args>(args)...);
577 template <
typename T,
typename... Args>
579 ::new (static_cast<void*>(p)) T(std::forward<Args>(args)...);
582 template <
typename A,
typename T>
584 T* p) -> decltype(
a.destroy(p)) {
587 template <
typename T>
592 template <
typename A>
597 return (std::numeric_limits<size_type>::max)() /
sizeof(value_type);
600 template <
typename A>
602 -> decltype(
a.select_on_container_copy_construction()) {
603 return a.select_on_container_copy_construction();
611 namespace memory_internal {
615 template <
typename Alloc>
639 template <
typename Alloc>
644 #if defined(ABSL_ALLOCATOR_NOTHROW) && ABSL_ALLOCATOR_NOTHROW 645 template <
typename T>
652 namespace memory_internal {
653 template <
typename Allocator,
typename Iterator,
typename... Args>
655 const Args&... args) {
656 for (Iterator cur = first; cur != last; ++cur) {
662 while (cur != first) {
671 template <
typename Allocator,
typename Iterator,
typename InputIterator>
673 InputIterator last) {
674 for (Iterator cur = destination; first != last;
675 static_cast<void>(++cur), static_cast<void>(++first)) {
681 while (cur != destination) {
692 #endif // ABSL_MEMORY_MEMORY_H_ memory_internal::ExtractOrT< memory_internal::GetIsAlwaysEqual, Alloc, typename std::is_empty< Alloc >::type > is_always_equal
typename T::template rebind< U > type
static pointer pointer_to(element_type &r)
memory_internal::MakeUniqueResult< T >::scalar make_unique(Args &&... args)
static Alloc select_on_container_copy_construction_impl(char, const Alloc &a)
typename RebindFirstArg< T, U >::type type
typename RebindFirstArg< T, U >::type type
static void deallocate(Alloc &a, pointer p, size_type n)
static pointer allocate(Alloc &a, size_type n, const_void_pointer hint)
std::unique_ptr< T > scalar
typename Alloc::is_nothrow GetIsNothrow
typename memory_internal::RebindAlloc< Alloc, T >::type rebind_alloc
typename T::propagate_on_container_move_assignment GetPropagateOnContainerMoveAssignment
std::unique_ptr< T > WrapUnique(T *ptr)
typename T::void_pointer GetVoidPointer
typename std::remove_extent< T >::type remove_extent_t
memory_internal::ExtractOrT< memory_internal::GetDifferenceType, Alloc, typename absl::pointer_traits< pointer >::difference_type > difference_type
static void destroy(Alloc &a, T *p)
static auto destroy_impl(int, A &a, T *p) -> decltype(a.destroy(p))
static pointer allocate(Alloc &a, size_type n)
typename GetFirstArg< Ptr >::type type
typename T::is_always_equal GetIsAlwaysEqual
static auto construct_impl(int, A &a, Args &&... args) -> decltype(a.construct(std::forward< Args >(args)...))
typename T::size_type GetSizeType
memory_internal::ExtractOrT< memory_internal::GetPropagateOnContainerMoveAssignment, Alloc, std::false_type > propagate_on_container_move_assignment
std::shared_ptr< T > ShareUniquePtr(std::unique_ptr< T, D > &&ptr)
#define ABSL_INTERNAL_CATCH_ANY
memory_internal::ExtractOrT< memory_internal::GetSizeType, Alloc, typename std::make_unsigned< difference_type >::type > size_type
typename T::const_pointer GetConstPointer
typename T::element_type type
typename memory_internal::ElementType< Ptr >::type element_type
static size_type max_size(const Alloc &a)
static std::function< void(void *, Slot *)> destroy
typename ExtractOr< Extract, Obj, Default, void >::type ExtractOrT
void ConstructRange(Allocator &alloc, Iterator first, Iterator last, const Args &... args)
static auto max_size_impl(int, const A &a) -> decltype(a.max_size())
void CopyRange(Allocator &alloc, Iterator destination, InputIterator first, InputIterator last)
static auto select_on_container_copy_construction_impl(int, const A &a) -> decltype(a.select_on_container_copy_construction())
memory_internal::ExtractOrT< memory_internal::GetPointer, Alloc, value_type * > pointer
auto RawPtr(T &&ptr) -> decltype(std::addressof(*ptr))
memory_internal::ExtractOrT< memory_internal::GetConstVoidPointer, Alloc, typename absl::pointer_traits< pointer >::template rebind< const void > > const_void_pointer
static auto allocate_impl(int, A &a, size_type n, const_void_pointer hint) -> decltype(a.allocate(n, hint))
static std::function< void(void *, Slot *, Slot)> construct
typename Alloc::value_type value_type
static size_type max_size_impl(char, const Alloc &)
typename type_traits_internal::VoidTImpl< Ts... >::type void_t
std::unique_ptr< T[]> array
typename T::difference_type GetDifferenceType
static pointer allocate_impl(char, Alloc &a, size_type n, const_void_pointer)
typename T::template rebind< U >::other type
static Alloc select_on_container_copy_construction(const Alloc &a)
memory_internal::MakeUniqueResult< T >::invalid make_unique(Args &&...)=delete
typename T::propagate_on_container_copy_assignment GetPropagateOnContainerCopyAssignment
memory_internal::ExtractOrT< memory_internal::GetPropagateOnContainerSwap, Alloc, std::false_type > propagate_on_container_swap
#define ABSL_INTERNAL_TRY
std::weak_ptr< T > WeakenPtr(const std::shared_ptr< T > &ptr)
static pointer pointer_to(element_type &r) noexcept
#define ABSL_INTERNAL_RETHROW
std::allocator< int > alloc
memory_internal::ExtractOrT< memory_internal::GetVoidPointer, Alloc, typename absl::pointer_traits< pointer >::template rebind< void > > void_pointer
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
typename memory_internal::RebindPtr< Ptr, U >::type rebind
typename T::propagate_on_container_swap GetPropagateOnContainerSwap
memory_internal::ExtractOrT< memory_internal::GetDifferenceType, Ptr, std::ptrdiff_t > difference_type
constexpr bool HasRebindAlloc(...)
typename T::const_void_pointer GetConstVoidPointer
memory_internal::ExtractOrT< memory_internal::GetConstPointer, Alloc, typename absl::pointer_traits< pointer >::template rebind< const value_type > > const_pointer
typename T::pointer GetPointer
static void construct(Alloc &a, T *p, Args &&... args)
static void destroy_impl(char, Alloc &, T *p)
memory_internal::ExtractOrT< memory_internal::GetPropagateOnContainerCopyAssignment, Alloc, std::false_type > propagate_on_container_copy_assignment
static void construct_impl(char, Alloc &, T *p, Args &&... args)
std::ptrdiff_t difference_type