// Allocator traits -*- C++ -*-
-// Copyright (C) 2011-2022 Free Software Foundation, Inc.
+// Copyright (C) 2011-2024 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
_GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus >= 201103L
-#define __cpp_lib_allocator_traits_is_always_equal 201411L
-
/// @cond undocumented
struct __allocator_traits_base
{
template<typename _Tp, typename _Up, typename = void>
- struct __rebind : __replace_first_arg<_Tp, _Up> { };
+ struct __rebind : __replace_first_arg<_Tp, _Up>
+ {
+ static_assert(is_same<
+ typename __replace_first_arg<_Tp, typename _Tp::value_type>::type,
+ _Tp>::value,
+ "allocator_traits<A>::rebind_alloc<A::value_type> must be A");
+ };
template<typename _Tp, typename _Up>
struct __rebind<_Tp, _Up,
__void_t<typename _Tp::template rebind<_Up>::other>>
- { using type = typename _Tp::template rebind<_Up>::other; };
+ {
+ using type = typename _Tp::template rebind<_Up>::other;
+
+ static_assert(is_same<
+ typename _Tp::template rebind<typename _Tp::value_type>::other,
+ _Tp>::value,
+ "allocator_traits<A>::rebind_alloc<A::value_type> must be A");
+ };
protected:
template<typename _Tp>
};
#if _GLIBCXX_HOSTED
-
-#if __cplusplus > 201703L
-# define __cpp_lib_constexpr_dynamic_alloc 201907L
-#endif
-
/// Partial specialization for std::allocator.
template<typename _Tp>
struct allocator_traits<allocator<_Tp>>
*
* Calls @c a.allocate(n)
*/
- _GLIBCXX_NODISCARD static _GLIBCXX20_CONSTEXPR pointer
+ [[__nodiscard__,__gnu__::__always_inline__]]
+ static _GLIBCXX20_CONSTEXPR pointer
allocate(allocator_type& __a, size_type __n)
{ return __a.allocate(__n); }
*
* Returns <tt> a.allocate(n, hint) </tt>
*/
- _GLIBCXX_NODISCARD static _GLIBCXX20_CONSTEXPR pointer
- allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
+ [[__nodiscard__,__gnu__::__always_inline__]]
+ static _GLIBCXX20_CONSTEXPR pointer
+ allocate(allocator_type& __a, size_type __n,
+ [[maybe_unused]] const_void_pointer __hint)
{
#if __cplusplus <= 201703L
return __a.allocate(__n, __hint);
*
* Calls <tt> a.deallocate(p, n) </tt>
*/
+ [[__gnu__::__always_inline__]]
static _GLIBCXX20_CONSTEXPR void
deallocate(allocator_type& __a, pointer __p, size_type __n)
{ __a.deallocate(__p, __n); }
* `std::construct_at(__p, std::forward<_Args>(__args)...)` instead.
*/
template<typename _Up, typename... _Args>
+ [[__gnu__::__always_inline__]]
static _GLIBCXX20_CONSTEXPR void
construct(allocator_type& __a __attribute__((__unused__)), _Up* __p,
_Args&&... __args)
* Calls @c __a.destroy(__p).
*/
template<typename _Up>
+ [[__gnu__::__always_inline__]]
static _GLIBCXX20_CONSTEXPR void
destroy(allocator_type& __a __attribute__((__unused__)), _Up* __p)
noexcept(is_nothrow_destructible<_Up>::value)
* @param __a An allocator.
* @return @c __a.max_size()
*/
+ [[__gnu__::__always_inline__]]
static _GLIBCXX20_CONSTEXPR size_type
max_size(const allocator_type& __a __attribute__((__unused__))) noexcept
{
* @param __rhs An allocator.
* @return @c __rhs
*/
+ [[__gnu__::__always_inline__]]
static _GLIBCXX20_CONSTEXPR allocator_type
select_on_container_copy_construction(const allocator_type& __rhs)
{ return __rhs; }
* `std::construct_at(__p, std::forward<_Args>(__args)...)` instead.
*/
template<typename _Up, typename... _Args>
+ [[__gnu__::__always_inline__]]
static _GLIBCXX20_CONSTEXPR void
construct(allocator_type&, _Up* __p, _Args&&... __args)
noexcept(std::is_nothrow_constructible<_Up, _Args...>::value)
* Invokes the destructor for `*__p`.
*/
template<typename _Up>
+ [[__gnu__::__always_inline__]]
static _GLIBCXX20_CONSTEXPR void
destroy(allocator_type&, _Up* __p)
noexcept(is_nothrow_destructible<_Up>::value)
* @param __rhs An allocator.
* @return `__rhs`
*/
+ [[__gnu__::__always_inline__]]
static _GLIBCXX20_CONSTEXPR allocator_type
select_on_container_copy_construction(const allocator_type& __rhs)
{ return __rhs; }
/// @cond undocumented
#if __cplusplus < 201703L
template<typename _Alloc>
+ [[__gnu__::__always_inline__]]
inline void
__do_alloc_on_copy(_Alloc& __one, const _Alloc& __two, true_type)
{ __one = __two; }
template<typename _Alloc>
+ [[__gnu__::__always_inline__]]
inline void
__do_alloc_on_copy(_Alloc&, const _Alloc&, false_type)
{ }
#endif
template<typename _Alloc>
+ [[__gnu__::__always_inline__]]
_GLIBCXX14_CONSTEXPR inline void
__alloc_on_copy(_Alloc& __one, const _Alloc& __two)
{
- typedef allocator_traits<_Alloc> __traits;
- typedef typename __traits::propagate_on_container_copy_assignment __pocca;
+ using __traits = allocator_traits<_Alloc>;
+ using __pocca =
+ typename __traits::propagate_on_container_copy_assignment::type;
#if __cplusplus >= 201703L
if constexpr (__pocca::value)
__one = __two;
}
template<typename _Alloc>
+ [[__gnu__::__always_inline__]]
constexpr _Alloc
__alloc_on_copy(const _Alloc& __a)
{
#if __cplusplus < 201703L
template<typename _Alloc>
+ [[__gnu__::__always_inline__]]
inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two, true_type)
{ __one = std::move(__two); }
template<typename _Alloc>
+ [[__gnu__::__always_inline__]]
inline void __do_alloc_on_move(_Alloc&, _Alloc&, false_type)
{ }
#endif
template<typename _Alloc>
+ [[__gnu__::__always_inline__]]
_GLIBCXX14_CONSTEXPR inline void
__alloc_on_move(_Alloc& __one, _Alloc& __two)
{
- typedef allocator_traits<_Alloc> __traits;
- typedef typename __traits::propagate_on_container_move_assignment __pocma;
+ using __traits = allocator_traits<_Alloc>;
+ using __pocma
+ = typename __traits::propagate_on_container_move_assignment::type;
#if __cplusplus >= 201703L
if constexpr (__pocma::value)
__one = std::move(__two);
#if __cplusplus < 201703L
template<typename _Alloc>
+ [[__gnu__::__always_inline__]]
inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two, true_type)
{
using std::swap;
}
template<typename _Alloc>
+ [[__gnu__::__always_inline__]]
inline void __do_alloc_on_swap(_Alloc&, _Alloc&, false_type)
{ }
#endif
template<typename _Alloc>
+ [[__gnu__::__always_inline__]]
_GLIBCXX14_CONSTEXPR inline void
__alloc_on_swap(_Alloc& __one, _Alloc& __two)
{
- typedef allocator_traits<_Alloc> __traits;
- typedef typename __traits::propagate_on_container_swap __pocs;
+ using __traits = allocator_traits<_Alloc>;
+ using __pocs = typename __traits::propagate_on_container_swap::type;
#if __cplusplus >= 201703L
if constexpr (__pocs::value)
{
#if _GLIBCXX_HOSTED
template<typename _ForwardIterator, typename _Tp>
- _GLIBCXX20_CONSTEXPR
+ __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
inline void
_Destroy(_ForwardIterator __first, _ForwardIterator __last,
allocator<_Tp>&)
{
- _Destroy(__first, __last);
+ std::_Destroy(__first, __last);
}
#endif
/// @endcond