[PATCH] Cleanup std::inplace_vector implementation

François Dumont frs.dumont@gmail.com
Mon Sep 22 17:14:25 GMT 2025


Some minor points spotted while working on the _GLIBCXX_DEBUG 
implementation.

I'm surprised that gcc did not complained about the duplicated std::swap 
implementation. He seems to be smart enough to see that it is the same 
despite the different noexcept qualification.

     libstdc++: std::inplace_vector implementation cleaup

     Remove duplicated std::swap implementations.

     Remove use of std::ref in std::erase_if.

     libstdc++-v3/ChangeLog

             * include/std/inplace_vector: Remove refwrap.h include.
             (std::swap(inplace_vector<>&, inplace_vector<>&)): Remove 
the duplicated
             implementation at std namespace level. Keep the friend 
inline one.
             (std::erase_if): Remove std::ref usage.

23_containers/inplace_vector tests run under Linux x86_64.

Ok to commit ?

François
-------------- next part --------------
diff --git a/libstdc++-v3/include/std/inplace_vector b/libstdc++-v3/include/std/inplace_vector
index b5a81bed3c9..02dfb8cd389 100644
--- a/libstdc++-v3/include/std/inplace_vector
+++ b/libstdc++-v3/include/std/inplace_vector
@@ -42,7 +42,6 @@
 #include <bits/ranges_base.h> // borrowed_iterator_t, __detail::__container_compatible_range
 #include <bits/ranges_util.h> // subrange
 #include <bits/ranges_uninitialized.h>
-#include <bits/refwrap.h>
 #include <bits/stl_construct.h>
 #include <bits/stl_uninitialized.h>
 #include <bits/stl_algo.h> // rotate
@@ -824,6 +823,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 						      __detail::__synth3way);
       }
 
+      // [inplace.vector.special], specialized algorithms
       constexpr friend void
       swap(inplace_vector& __x, inplace_vector& __y)
       noexcept(is_nothrow_swappable_v<_Tp> && is_nothrow_move_constructible_v<_Tp>)
@@ -908,13 +908,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	}
     };
 
-  // [inplace.vector.special], specialized algorithms
-  template<typename _Tp, size_t _Nm>
-    constexpr void
-    swap(inplace_vector<_Tp, _Nm>& __x, inplace_vector<_Tp, _Nm>& __y)
-    noexcept(noexcept(__x.swap(__y)))
-    { __x.swap(__y); }
-
   // specialization for zero capacity, that is required to be trivally copyable
   // and empty regardless of _Tp.
   template<typename _Tp>
@@ -1343,7 +1336,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       const auto __osz = __cont.size();
       const auto __end = __cont.end();
       auto __removed = std::__remove_if(__cont.begin(), __end,
-					__ops::__pred_iter(std::ref(__pred)));
+					__ops::__pred_iter(__pred));
       if (__removed != __end)
 	{
 	  __cont.erase(__niter_wrap(__cont.begin(), __removed),


More information about the Libstdc++ mailing list