// -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H #define _LIBCPP___MEMORY_ALLOCATOR_TRAITS_H #include <__config> #include <__cstddef/size_t.h> #include <__fwd/memory.h> #include <__memory/construct_at.h> #include <__memory/pointer_traits.h> #include <__type_traits/detected_or.h> #include <__type_traits/enable_if.h> #include <__type_traits/is_constructible.h> #include <__type_traits/is_empty.h> #include <__type_traits/is_same.h> #include <__type_traits/make_unsigned.h> #include <__type_traits/remove_reference.h> #include <__type_traits/void_t.h> #include <__utility/declval.h> #include <__utility/forward.h> #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif _LIBCPP_PUSH_MACROS #include <__undef_macros> _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_SUPPRESS_DEPRECATED_PUSH // __pointer template using __pointer_member _LIBCPP_NODEBUG = typename _Tp::pointer; template using __pointer _LIBCPP_NODEBUG = __detected_or_t<_Tp*, __pointer_member, __libcpp_remove_reference_t<_Alloc> >; // This trait returns _Alias<_Alloc> if that's well-formed, and _Ptr rebound to _Tp otherwise template class _Alias, class _Ptr, class _Tp, class = void> struct __rebind_or_alias_pointer { #ifdef _LIBCPP_CXX03_LANG using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<_Tp>::other; #else using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::template rebind<_Tp>; #endif }; template class _Alias> struct __rebind_or_alias_pointer<_Alloc, _Alias, _Ptr, _Tp, __void_t<_Alias<_Alloc> > > { using type _LIBCPP_NODEBUG = _Alias<_Alloc>; }; // __const_pointer template using __const_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_pointer; template using __const_pointer_t _LIBCPP_NODEBUG = typename __rebind_or_alias_pointer<_Alloc, __const_pointer_member, _Ptr, const _Tp>::type; _LIBCPP_SUPPRESS_DEPRECATED_POP // __void_pointer template using __void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::void_pointer; template using __void_pointer_t _LIBCPP_NODEBUG = typename __rebind_or_alias_pointer<_Alloc, __void_pointer_member, _Ptr, void>::type; // __const_void_pointer template using __const_void_pointer_member _LIBCPP_NODEBUG = typename _Alloc::const_void_pointer; template using __const_void_pointer_t _LIBCPP_NODEBUG = typename __rebind_or_alias_pointer<_Alloc, __const_void_pointer_member, _Ptr, const void>::type; // __size_type template using __size_type_member _LIBCPP_NODEBUG = typename _Tp::size_type; template using __size_type _LIBCPP_NODEBUG = __detected_or_t<__make_unsigned_t<_DiffType>, __size_type_member, _Alloc>; // __alloc_traits_difference_type template struct __alloc_traits_difference_type { using type _LIBCPP_NODEBUG = typename pointer_traits<_Ptr>::difference_type; }; template struct __alloc_traits_difference_type<_Alloc, _Ptr, __void_t > { using type _LIBCPP_NODEBUG = typename _Alloc::difference_type; }; // __propagate_on_container_copy_assignment template using __propagate_on_container_copy_assignment_member _LIBCPP_NODEBUG = typename _Tp::propagate_on_container_copy_assignment; template using __propagate_on_container_copy_assignment _LIBCPP_NODEBUG = __detected_or_t; // __propagate_on_container_move_assignment template using __propagate_on_container_move_assignment_member _LIBCPP_NODEBUG = typename _Tp::propagate_on_container_move_assignment; template using __propagate_on_container_move_assignment _LIBCPP_NODEBUG = __detected_or_t; // __propagate_on_container_swap template using __propagate_on_container_swap_member _LIBCPP_NODEBUG = typename _Tp::propagate_on_container_swap; template using __propagate_on_container_swap _LIBCPP_NODEBUG = __detected_or_t; _LIBCPP_SUPPRESS_DEPRECATED_PUSH // __is_always_equal template using __is_always_equal_member _LIBCPP_NODEBUG = typename _Tp::is_always_equal; template using __is_always_equal _LIBCPP_NODEBUG = __detected_or_t::type, __is_always_equal_member, _Alloc>; // __allocator_traits_rebind template inline const bool __has_rebind_other_v = false; template inline const bool __has_rebind_other_v<_Tp, _Up, __void_t::other> > = true; template > struct __allocator_traits_rebind { static_assert(__has_rebind_other_v<_Tp, _Up>, "This allocator has to implement rebind"); using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other; }; template