[libcxx-commits] [libcxx] [libc++] Optimize vector::erase (PR #213916)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Aug 12 07:20:37 PDT 2026
================
@@ -431,6 +431,44 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __uninitialized_allocat
}
}
+// __uninitialized_allocator_relocate_forward relocates the objects in [__first, __last) into __result
+// element-by-element from __first to __last. Relocation means that the objects in [__first, __last) are placed into
+// __result as-if by move-construct and destroy, except that the move constructor and destructor may never be called if
+// they are known to be equivalent to a memcpy.
+//
+// Preconditions: At __result there is no object and [__first, __last) contains objects
+// Postconditions: __result contains the objects from [__first, __last) and
+// [__first, __last) doesn't contain any objects
+//
+// The strong exception guarantee is provided.
+template <class _Alloc, class _ContiguousIterator>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __uninitialized_allocator_relocate_forward(
+ _Alloc& __alloc, _ContiguousIterator __first, _ContiguousIterator __last, _ContiguousIterator __result) {
+ static_assert(__libcpp_is_contiguous_iterator<_ContiguousIterator>::value, "");
+ using _ValueType = typename iterator_traits<_ContiguousIterator>::value_type;
+ static_assert(
+ __is_nothrow_relocatable_v<_ValueType> && __allocator_has_trivial_move_construct_v<_Alloc, _ValueType> &&
----------------
ldionne wrote:
I don't think we need nothrow-relocatable in this algorithm. We can destroy the whole range if an exception is thrown. Whether we decide to use it from `erase` or not for potentially throwing types is a separate decision.
https://github.com/llvm/llvm-project/pull/213916
More information about the libcxx-commits
mailing list