]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Move allocator-related helpers to <bits/alloc_traits.h>
authorJonathan Wakely <jwakely@redhat.com>
Fri, 16 Sep 2022 20:29:44 +0000 (21:29 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 16 Sep 2022 20:35:43 +0000 (21:35 +0100)
The __alloc_swap and __shrink_to_fit_aux helpers are not specific to
std::allocator, so don't belong in <bits/allocator.h>. This also
simplifies enabling <memory> for freestanding, as now we can just omit
the whole of <bits/allocator.h> for freestanding.

libstdc++-v3/ChangeLog:

* include/bits/alloc_traits.h (__alloc_swap)
(__shrink_to_fit_aux): Move here, from ...
* include/bits/allocator.h: ... here.
* include/ext/alloc_traits.h: Do not include allocator.h.

libstdc++-v3/include/bits/alloc_traits.h
libstdc++-v3/include/bits/allocator.h
libstdc++-v3/include/ext/alloc_traits.h

index f9ca37fd7d6f9965db36143b0614c7ef0b75bb16..35bdf6ecf98e74a8fcbc4fb39bbd4655643cc0da 100644 (file)
@@ -824,6 +824,54 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// @cond undocumented
 
+  // To implement Option 3 of DR 431.
+  template<typename _Alloc, bool = __is_empty(_Alloc)>
+    struct __alloc_swap
+    { static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } };
+
+  template<typename _Alloc>
+    struct __alloc_swap<_Alloc, false>
+    {
+      static void
+      _S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT
+      {
+       // Precondition: swappable allocators.
+       if (__one != __two)
+         swap(__one, __two);
+      }
+    };
+
+#if __cplusplus >= 201103L
+  template<typename _Tp, bool
+    = __or_<is_copy_constructible<typename _Tp::value_type>,
+            is_nothrow_move_constructible<typename _Tp::value_type>>::value>
+    struct __shrink_to_fit_aux
+    { static bool _S_do_it(_Tp&) noexcept { return false; } };
+
+  template<typename _Tp>
+    struct __shrink_to_fit_aux<_Tp, true>
+    {
+      _GLIBCXX20_CONSTEXPR
+      static bool
+      _S_do_it(_Tp& __c) noexcept
+      {
+#if __cpp_exceptions
+       try
+         {
+           _Tp(__make_move_if_noexcept_iterator(__c.begin()),
+               __make_move_if_noexcept_iterator(__c.end()),
+               __c.get_allocator()).swap(__c);
+           return true;
+         }
+       catch(...)
+         { return false; }
+#else
+       return false;
+#endif
+      }
+    };
+#endif
+
   /**
    * Destroy a range of objects using the supplied allocator.  For
    * non-default allocators we do not optimize away invocation of
index c39166e24feb6f0ce31a3607ebfba70f8191e383..54f5acf85d7a6583b05ee2952546d7a1a95d26b9 100644 (file)
@@ -279,57 +279,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   // Undefine.
 #undef __allocator_base
 
-  /// @cond undocumented
-
-  // To implement Option 3 of DR 431.
-  template<typename _Alloc, bool = __is_empty(_Alloc)>
-    struct __alloc_swap
-    { static void _S_do_it(_Alloc&, _Alloc&) _GLIBCXX_NOEXCEPT { } };
-
-  template<typename _Alloc>
-    struct __alloc_swap<_Alloc, false>
-    {
-      static void
-      _S_do_it(_Alloc& __one, _Alloc& __two) _GLIBCXX_NOEXCEPT
-      {
-       // Precondition: swappable allocators.
-       if (__one != __two)
-         swap(__one, __two);
-      }
-    };
-
-#if __cplusplus >= 201103L
-  template<typename _Tp, bool
-    = __or_<is_copy_constructible<typename _Tp::value_type>,
-            is_nothrow_move_constructible<typename _Tp::value_type>>::value>
-    struct __shrink_to_fit_aux
-    { static bool _S_do_it(_Tp&) noexcept { return false; } };
-
-  template<typename _Tp>
-    struct __shrink_to_fit_aux<_Tp, true>
-    {
-      _GLIBCXX20_CONSTEXPR
-      static bool
-      _S_do_it(_Tp& __c) noexcept
-      {
-#if __cpp_exceptions
-       try
-         {
-           _Tp(__make_move_if_noexcept_iterator(__c.begin()),
-               __make_move_if_noexcept_iterator(__c.end()),
-               __c.get_allocator()).swap(__c);
-           return true;
-         }
-       catch(...)
-         { return false; }
-#else
-       return false;
-#endif
-      }
-    };
-#endif
-  /// @endcond
-
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 
index 1d7d9598cb2fa6fdcf5b32184e6f6f91b66a30cc..c9547c7305c6bd575ea983d8d4bb74cf289f8061 100644 (file)
@@ -32,9 +32,6 @@
 #pragma GCC system_header
 
 # include <bits/alloc_traits.h>
-#if __cplusplus < 201103L
-# include <bits/allocator.h>  // for __alloc_swap
-#endif
 
 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
 {