[libcxx-commits] [libcxx] [libc++] Accept iterators instead of raw pointers in __uninitialized_allocator_relocate (PR #114552)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Nov 5 11:51:47 PST 2024


================
@@ -611,20 +611,22 @@ struct __allocator_has_trivial_destroy<allocator<_Tp>, _Up> : true_type {};
 //                 [__first, __last) doesn't contain any objects
 //
 // The strong exception guarantee is provided if any of the following are true:
-// - is_nothrow_move_constructible<_Tp>
-// - is_copy_constructible<_Tp>
-// - __libcpp_is_trivially_relocatable<_Tp>
-template <class _Alloc, class _Tp>
-_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
-__uninitialized_allocator_relocate(_Alloc& __alloc, _Tp* __first, _Tp* __last, _Tp* __result) {
+// - is_nothrow_move_constructible<_ValueType>
+// - is_copy_constructible<_ValueType>
+// - __libcpp_is_trivially_relocatable<_ValueType>
+template <class _Alloc, class _ContiguousIterator>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void __uninitialized_allocator_relocate(
+    _Alloc& __alloc, _ContiguousIterator __first, _ContiguousIterator __last, _ContiguousIterator __result) {
+  static_assert(__libcpp_is_contiguous_iterator<_ContiguousIterator>::value, "");
----------------
ldionne wrote:

Well, actually, I would suggest still accepting contiguous iterators inside `__uninitialized_allocator_relocate` since that makes sense, but then we'd have to still call `__to_address` from `std::vector` when we call the algorithm. So at least we generalize the algorithm, but we can't actually simplify the call sites.

https://github.com/llvm/llvm-project/pull/114552


More information about the libcxx-commits mailing list