]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/bits/alloc_traits.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / alloc_traits.h
index 8479bfd612f6ea831a773b441c098f8d6aae5019..5e661e047416957d8232e65585285cc95dd5f5ea 100644 (file)
@@ -1,6 +1,6 @@
 // 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
@@ -45,18 +45,29 @@ namespace std _GLIBCXX_VISIBILITY(default)
 _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>
@@ -405,11 +416,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     };
 
 #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>>
@@ -463,7 +469,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *
        *  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); }
 
@@ -477,8 +484,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *
        *  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);
@@ -495,6 +504,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *
        *  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); }
@@ -511,6 +521,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  `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)
@@ -531,6 +542,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  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)
@@ -547,6 +559,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  @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
       {
@@ -562,6 +575,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  @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; }
@@ -633,6 +647,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  `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)
@@ -646,6 +661,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  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)
@@ -660,6 +676,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        *  @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; }
@@ -669,22 +686,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   /// @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;
@@ -694,6 +715,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
   template<typename _Alloc>
+    [[__gnu__::__always_inline__]]
     constexpr _Alloc
     __alloc_on_copy(const _Alloc& __a)
     {
@@ -703,20 +725,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #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);
@@ -727,6 +753,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cplusplus < 201703L
   template<typename _Alloc>
+    [[__gnu__::__always_inline__]]
     inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two, true_type)
     {
       using std::swap;
@@ -734,16 +761,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
   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)
        {
@@ -904,12 +933,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #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