[libcxx-commits] [libcxx] [libc++] Fix {deque, vector}::append_range assuming too much about the types (PR #162438)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 8 07:48:12 PDT 2025
================
@@ -489,7 +490,21 @@ class vector {
#if _LIBCPP_STD_VER >= 23
template <_ContainerCompatibleRange<_Tp> _Range>
_LIBCPP_HIDE_FROM_ABI constexpr void append_range(_Range&& __range) {
- insert_range(end(), std::forward<_Range>(__range));
+ if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) {
+ auto __size = ranges::distance(__range);
+ if (__size < __cap_ - __end_) {
----------------
ldionne wrote:
```suggestion
auto __len = ranges::distance(__range);
if (__len < __cap_ - __end_) {
```
`__size_` will be a member variable of the vector with size-based vector, and it's also confusing with `size()`. I read it incorrectly initially. `__len` says that it's a length or size, but it's different enough from `size()` so that there's no confusion possible.
https://github.com/llvm/llvm-project/pull/162438
More information about the libcxx-commits
mailing list