aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/__memory/allocator_traits.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-02-11 12:38:11 +0000
commite3b557809604d036af6e00c60f012c2025b59a5e (patch)
tree8a11ba2269a3b669601e2fd41145b174008f4da8 /libcxx/include/__memory/allocator_traits.h
parent08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff)
Diffstat (limited to 'libcxx/include/__memory/allocator_traits.h')
-rw-r--r--libcxx/include/__memory/allocator_traits.h63
1 files changed, 34 insertions, 29 deletions
diff --git a/libcxx/include/__memory/allocator_traits.h b/libcxx/include/__memory/allocator_traits.h
index 5215556cdf3c..3a23b47c74b3 100644
--- a/libcxx/include/__memory/allocator_traits.h
+++ b/libcxx/include/__memory/allocator_traits.h
@@ -13,9 +13,16 @@
#include <__config>
#include <__memory/construct_at.h>
#include <__memory/pointer_traits.h>
+#include <__type_traits/enable_if.h>
+#include <__type_traits/is_copy_constructible.h>
+#include <__type_traits/is_empty.h>
+#include <__type_traits/is_move_constructible.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 <limits>
-#include <type_traits>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -28,12 +35,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
#define _LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(NAME, PROPERTY) \
template <class _Tp, class = void> struct NAME : false_type { }; \
- template <class _Tp> struct NAME<_Tp, typename __void_t<typename _Tp:: PROPERTY >::type> : true_type { }
+ template <class _Tp> struct NAME<_Tp, __void_t<typename _Tp:: PROPERTY > > : true_type { }
// __pointer
_LIBCPP_ALLOCATOR_TRAITS_HAS_XXX(__has_pointer, pointer);
template <class _Tp, class _Alloc,
- class _RawAlloc = typename remove_reference<_Alloc>::type,
+ class _RawAlloc = __libcpp_remove_reference_t<_Alloc>,
bool = __has_pointer<_RawAlloc>::value>
struct __pointer {
using type _LIBCPP_NODEBUG = typename _RawAlloc::pointer;
@@ -152,13 +159,12 @@ _LIBCPP_SUPPRESS_DEPRECATED_PUSH
template <class _Tp, class _Up, class = void>
struct __has_rebind_other : false_type { };
template <class _Tp, class _Up>
-struct __has_rebind_other<_Tp, _Up, typename __void_t<
- typename _Tp::template rebind<_Up>::other
->::type> : true_type { };
+struct __has_rebind_other<_Tp, _Up, __void_t<typename _Tp::template rebind<_Up>::other> > : true_type { };
template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
struct __allocator_traits_rebind {
- using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other;
+ static_assert(__has_rebind_other<_Tp, _Up>::value, "This allocator has to implement rebind");
+ using type _LIBCPP_NODEBUG = typename _Tp::template rebind<_Up>::other;
};
template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true> {
@@ -181,7 +187,7 @@ struct __has_allocate_hint : false_type { };
template <class _Alloc, class _SizeType, class _ConstVoidPtr>
struct __has_allocate_hint<_Alloc, _SizeType, _ConstVoidPtr, decltype(
- (void)declval<_Alloc>().allocate(declval<_SizeType>(), declval<_ConstVoidPtr>())
+ (void)std::declval<_Alloc>().allocate(std::declval<_SizeType>(), std::declval<_ConstVoidPtr>())
)> : true_type { };
// __has_construct
@@ -190,7 +196,7 @@ struct __has_construct_impl : false_type { };
template <class _Alloc, class ..._Args>
struct __has_construct_impl<decltype(
- (void)declval<_Alloc>().construct(declval<_Args>()...)
+ (void)std::declval<_Alloc>().construct(std::declval<_Args>()...)
), _Alloc, _Args...> : true_type { };
template <class _Alloc, class ..._Args>
@@ -202,7 +208,7 @@ struct __has_destroy : false_type { };
template <class _Alloc, class _Pointer>
struct __has_destroy<_Alloc, _Pointer, decltype(
- (void)declval<_Alloc>().destroy(declval<_Pointer>())
+ (void)std::declval<_Alloc>().destroy(std::declval<_Pointer>())
)> : true_type { };
// __has_max_size
@@ -211,7 +217,7 @@ struct __has_max_size : false_type { };
template <class _Alloc>
struct __has_max_size<_Alloc, decltype(
- (void)declval<_Alloc&>().max_size()
+ (void)std::declval<_Alloc&>().max_size()
)> : true_type { };
// __has_select_on_container_copy_construction
@@ -220,7 +226,7 @@ struct __has_select_on_container_copy_construction : false_type { };
template <class _Alloc>
struct __has_select_on_container_copy_construction<_Alloc, decltype(
- (void)declval<_Alloc>().select_on_container_copy_construction()
+ (void)std::declval<_Alloc>().select_on_container_copy_construction()
)> : true_type { };
_LIBCPP_SUPPRESS_DEPRECATED_POP
@@ -257,14 +263,14 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
};
#endif // _LIBCPP_CXX03_LANG
- _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static pointer allocate(allocator_type& __a, size_type __n) {
return __a.allocate(__n);
}
template <class _Ap = _Alloc, class =
__enable_if_t<__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> >
- _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint) {
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
return __a.allocate(__n, __hint);
@@ -272,19 +278,19 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
}
template <class _Ap = _Alloc, class = void, class =
__enable_if_t<!__has_allocate_hint<_Ap, size_type, const_void_pointer>::value> >
- _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer) {
return __a.allocate(__n);
}
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT {
__a.deallocate(__p, __n);
}
template <class _Tp, class... _Args, class =
__enable_if_t<__has_construct<allocator_type, _Tp*, _Args...>::value> >
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args) {
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
__a.construct(__p, _VSTD::forward<_Args>(__args)...);
@@ -292,7 +298,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
}
template <class _Tp, class... _Args, class = void, class =
__enable_if_t<!__has_construct<allocator_type, _Tp*, _Args...>::value> >
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static void construct(allocator_type&, _Tp* __p, _Args&&... __args) {
#if _LIBCPP_STD_VER > 17
_VSTD::construct_at(__p, _VSTD::forward<_Args>(__args)...);
@@ -303,7 +309,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
template <class _Tp, class =
__enable_if_t<__has_destroy<allocator_type, _Tp*>::value> >
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static void destroy(allocator_type& __a, _Tp* __p) {
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
__a.destroy(__p);
@@ -311,7 +317,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
}
template <class _Tp, class = void, class =
__enable_if_t<!__has_destroy<allocator_type, _Tp*>::value> >
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static void destroy(allocator_type&, _Tp* __p) {
#if _LIBCPP_STD_VER > 17
_VSTD::destroy_at(__p);
@@ -322,7 +328,7 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
template <class _Ap = _Alloc, class =
__enable_if_t<__has_max_size<const _Ap>::value> >
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static size_type max_size(const allocator_type& __a) _NOEXCEPT {
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
return __a.max_size();
@@ -330,33 +336,32 @@ struct _LIBCPP_TEMPLATE_VIS allocator_traits
}
template <class _Ap = _Alloc, class = void, class =
__enable_if_t<!__has_max_size<const _Ap>::value> >
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static size_type max_size(const allocator_type&) _NOEXCEPT {
return numeric_limits<size_type>::max() / sizeof(value_type);
}
template <class _Ap = _Alloc, class =
__enable_if_t<__has_select_on_container_copy_construction<const _Ap>::value> >
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static allocator_type select_on_container_copy_construction(const allocator_type& __a) {
return __a.select_on_container_copy_construction();
}
template <class _Ap = _Alloc, class = void, class =
__enable_if_t<!__has_select_on_container_copy_construction<const _Ap>::value> >
- _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
static allocator_type select_on_container_copy_construction(const allocator_type& __a) {
return __a;
}
};
-template <class _Traits, class _Tp>
-struct __rebind_alloc_helper {
#ifndef _LIBCPP_CXX03_LANG
- using type _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>;
+template <class _Traits, class _Tp>
+using __rebind_alloc _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>;
#else
- using type = typename _Traits::template rebind_alloc<_Tp>::other;
+template <class _Traits, class _Tp>
+using __rebind_alloc = typename _Traits::template rebind_alloc<_Tp>::other;
#endif
-};
// __is_default_allocator
template <class _Tp>