[libcxx-commits] [libcxx] 334027f - [libc++] Avoid passing both sentinel and size around in vector (#214132)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 14 01:29:16 PDT 2026
Author: Nikolas Klauser
Date: 2026-10-14T10:29:11+02:00
New Revision: 334027fcd432039dd150aa7d3fd4a1a0d917493b
URL: https://github.com/llvm/llvm-project/commit/334027fcd432039dd150aa7d3fd4a1a0d917493b
DIFF: https://github.com/llvm/llvm-project/commit/334027fcd432039dd150aa7d3fd4a1a0d917493b.diff
LOG: [libc++] Avoid passing both sentinel and size around in vector (#214132)
Currently we are passing both the end iterator and the size of a range
around because we sometimes use one or the other. This makes the uses
consistently only rely on the size, which allows simplifying a bunch of
code.
Added:
Modified:
libcxx/include/__vector/vector.h
libcxx/include/memory
Removed:
################################################################################
diff --git a/libcxx/include/__vector/vector.h b/libcxx/include/__vector/vector.h
index aa8441e3f9554..37a25f20e65cd 100644
--- a/libcxx/include/__vector/vector.h
+++ b/libcxx/include/__vector/vector.h
@@ -346,7 +346,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
@@ -354,7 +354,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));
@@ -706,9 +706,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,
diff erence_type __n);
+ template <class _AlgPolicy, class _Iterator>
+ _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI void __assign_with_size(_Iterator __first,
diff erence_type __n);
template <class _AlgPolicy,
class _Iterator,
@@ -965,9 +964,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,
diff erence_type __n) {
+vector<_Tp, _Allocator>::__assign_with_size(_Iterator __first,
diff erence_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 9469766543c47..91bb0fbf33b4c 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