[libcxx-commits] [libcxx] [libc++] Avoid passing both sentinel and size around in vector (PR #214132)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 13 07:56:46 PDT 2026


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/214132

>From 604f328a63d22892ae6a7cf404712266c7a427b2 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 5 Aug 2026 06:35:31 +0200
Subject: [PATCH] [libc++] Avoid passing both sentinel and size around in
 vector

---
 libcxx/include/__vector/vector.h | 13 ++++++-------
 libcxx/include/memory            |  2 +-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index a93b890e90de1d..d964276bf858a6 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -343,7 +343,7 @@ class _LIBCPP_WARN_UNUSED vector {
                         is_constructible<value_type, typename iterator_traits<_ForwardIterator>::reference>::value,
                     int> = 0>
   _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void assign(_ForwardIterator __first, _ForwardIterator __last) {
-    __assign_with_size<_ClassicAlgPolicy>(__first, __last, std::distance(__first, __last));
+    __assign_with_size<_ClassicAlgPolicy>(__first, std::distance(__first, __last));
   }
 
 #if _LIBCPP_STD_VER >= 23
@@ -351,7 +351,7 @@ class _LIBCPP_WARN_UNUSED vector {
   _LIBCPP_HIDE_FROM_ABI constexpr void assign_range(_Range&& __range) {
     if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
       auto __n = static_cast<size_type>(ranges::distance(__range));
-      __assign_with_size<_RangeAlgPolicy>(ranges::begin(__range), ranges::end(__range), __n);
+      __assign_with_size<_RangeAlgPolicy>(ranges::begin(__range), __n);
 
     } else {
       __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
@@ -703,9 +703,8 @@ class _LIBCPP_WARN_UNUSED vector {
   // The `_Iterator` in `*_with_size` functions can be input-only only if called from `*_range` (since C++23).
   // Otherwise, `_Iterator` is a forward iterator.
 
-  template <class _AlgPolicy, class _Iterator, class _Sentinel>
-  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
-  __assign_with_size(_Iterator __first, _Sentinel __last, difference_type __n);
+  template <class _AlgPolicy, class _Iterator>
+  _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_size(_Iterator __first, difference_type __n);
 
   template <class _AlgPolicy,
             class _Iterator,
@@ -962,9 +961,9 @@ vector<_Tp, _Allocator>::__assign_with_sentinel(_Iterator __first, _Sentinel __l
 }
 
 template <class _Tp, class _Allocator>
-template <class _AlgPolicy, class _Iterator, class _Sentinel>
+template <class _AlgPolicy, class _Iterator>
 _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void
-vector<_Tp, _Allocator>::__assign_with_size(_Iterator __first, _Sentinel, difference_type __n) {
+vector<_Tp, _Allocator>::__assign_with_size(_Iterator __first, difference_type __n) {
   size_type __new_size = static_cast<size_type>(__n);
   if (__new_size <= capacity()) {
     auto const __size = size();
diff --git a/libcxx/include/memory b/libcxx/include/memory
index 9469766543c47c..91bb0fbf33b4c8 100644
--- a/libcxx/include/memory
+++ b/libcxx/include/memory
@@ -1019,7 +1019,7 @@ template<class Pointer = void, class Smart, class... Args>
 #    pragma GCC system_header
 #  endif
 
-#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 23
+#  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 17
 #    include <initializer_list>
 #  endif
 



More information about the libcxx-commits mailing list