[libcxx-commits] [libcxx] [libc++] Accept iterators instead of raw pointers in __uninitialized_allocator_relocate (PR #114552)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Nov 4 09:52:31 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, "");
----------------
frederick-vs-ja wrote:
It seems that we can't reliably use `static_assert` here.
Before C++20, this would reject user-defined fancy pointers. And strangely, even since C++20, it's not yet required that fancy pointers shall model `contiguous_iterator`. The requirements in [[allocator.requirements.general]/92](https://eel.is/c++draft/allocator.requirements.general#92) is a bit more looser than those for `contiguous_iterator`.
https://github.com/llvm/llvm-project/pull/114552
More information about the libcxx-commits
mailing list