// -*- C++ -*- //===----------------------------------------------------------------------===// // // Part of libcu++, the C++ Standard Library for your entire system, // 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 // SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. // //===----------------------------------------------------------------------===// #ifndef _LIBCUDACXX___MEMORY_ALLOCATOR_TRAITS_H #define _LIBCUDACXX___MEMORY_ALLOCATOR_TRAITS_H #include #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) # pragma GCC system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) # pragma clang system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) # pragma system_header #endif // no system header #include #include #include #include #include #include #include #include #include #include #include #include #include _CCCL_PUSH_MACROS _CCCL_NV_DIAG_SUPPRESS(1215) _LIBCUDACXX_BEGIN_NAMESPACE_STD #if _CCCL_STD_VER <= 2014 # define _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \ template \ struct NAME : false_type \ {}; \ template \ struct NAME<_Tp, __void_t> : true_type \ {} #else // ^^^ _CCCL_STD_VER <= 2014 ^^^ / vvv _CCCL_STD_VER >= 2017 vvv # define _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \ template \ inline constexpr bool NAME##_v = false; \ template \ inline constexpr bool NAME##_v<_Tp, __void_t> = true; #endif // _CCCL_STD_VER >= 2017 // __pointer _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_pointer, pointer); template , bool = _CCCL_TRAIT(__has_pointer, _RawAlloc)> struct __pointer { using type _LIBCUDACXX_NODEBUG_TYPE = typename _RawAlloc::pointer; }; template struct __pointer<_Tp, _Alloc, _RawAlloc, false> { using type _LIBCUDACXX_NODEBUG_TYPE = _Tp*; }; // __const_pointer _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_const_pointer, const_pointer); template struct __const_pointer { using type _LIBCUDACXX_NODEBUG_TYPE = typename _Alloc::const_pointer; }; template struct __const_pointer<_Tp, _Ptr, _Alloc, false> { using type _LIBCUDACXX_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind; }; // __void_pointer _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_void_pointer, void_pointer); template struct __void_pointer { using type _LIBCUDACXX_NODEBUG_TYPE = typename _Alloc::void_pointer; }; template struct __void_pointer<_Ptr, _Alloc, false> { using type _LIBCUDACXX_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind; }; // __const_void_pointer _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_const_void_pointer, const_void_pointer); template struct __const_void_pointer { using type _LIBCUDACXX_NODEBUG_TYPE = typename _Alloc::const_void_pointer; }; template struct __const_void_pointer<_Ptr, _Alloc, false> { using type _LIBCUDACXX_NODEBUG_TYPE = typename pointer_traits<_Ptr>::template rebind; }; // __size_type _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_size_type, size_type); template struct __size_type : make_unsigned<_DiffType> {}; template struct __size_type<_Alloc, _DiffType, true> { using type _LIBCUDACXX_NODEBUG_TYPE = typename _Alloc::size_type; }; // __alloc_traits_difference_type _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_alloc_traits_difference_type, difference_type); template struct __alloc_traits_difference_type { using type _LIBCUDACXX_NODEBUG_TYPE = typename pointer_traits<_Ptr>::difference_type; }; template struct __alloc_traits_difference_type<_Alloc, _Ptr, true> { using type _LIBCUDACXX_NODEBUG_TYPE = typename _Alloc::difference_type; }; // __propagate_on_container_copy_assignment _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_copy_assignment, propagate_on_container_copy_assignment); template struct __propagate_on_container_copy_assignment : false_type {}; template struct __propagate_on_container_copy_assignment<_Alloc, true> { using type _LIBCUDACXX_NODEBUG_TYPE = typename _Alloc::propagate_on_container_copy_assignment; }; // __propagate_on_container_move_assignment _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_move_assignment, propagate_on_container_move_assignment); template struct __propagate_on_container_move_assignment : false_type {}; template struct __propagate_on_container_move_assignment<_Alloc, true> { using type _LIBCUDACXX_NODEBUG_TYPE = typename _Alloc::propagate_on_container_move_assignment; }; // __propagate_on_container_swap _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_propagate_on_container_swap, propagate_on_container_swap); template struct __propagate_on_container_swap : false_type {}; template struct __propagate_on_container_swap<_Alloc, true> { using type _LIBCUDACXX_NODEBUG_TYPE = typename _Alloc::propagate_on_container_swap; }; // __is_always_equal _LIBCUDACXX_ALLOCATOR_TRAITS_HAS_XXX(__has_is_always_equal, is_always_equal); template struct __is_always_equal : is_empty<_Alloc> {}; template struct __is_always_equal<_Alloc, true> { using type _LIBCUDACXX_NODEBUG_TYPE = typename _Alloc::is_always_equal; }; // __allocator_traits_rebind _CCCL_SUPPRESS_DEPRECATED_PUSH template struct __has_rebind_other : false_type {}; template struct __has_rebind_other<_Tp, _Up, __void_t::other>> : true_type {}; template ::value> struct __allocator_traits_rebind { static_assert(__has_rebind_other<_Tp, _Up>::value, "This allocator has to implement rebind"); using type _LIBCUDACXX_NODEBUG_TYPE = typename _Tp::template rebind<_Up>::other; }; template