[libcxx-commits] [libcxx] [libc++] Optimize ranges::move{, _backward} for vector<bool>::iterator (PR #121109)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Feb 6 12:02:46 PST 2025
================
@@ -98,6 +100,14 @@ struct __move_impl {
}
}
+ template <class _Cp, bool _IsConst>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false> >
+ operator()(__bit_iterator<_Cp, _IsConst> __first,
+ __bit_iterator<_Cp, _IsConst> __last,
+ __bit_iterator<_Cp, false> __result) {
+ return std::__copy(__first, __last, __result);
----------------
winner245 wrote:
We can call `std::copy` instead of `std::__copy`. However, the expected return type here is `pair<__bit_iterator<_Cp, _IsConst>, __bit_iterator<_Cp, false>>`, while `std::copy` returns an iterator. So we would have to call an extra `std::make_pair` in addition to the call to `std::copy` as follows (the same applies to `copy_backward`)
```cpp
return std::make_pair(__last, std::copy(__first, __last, __result));
```
In contrast, `std::__copy` has the expected return type of `pair`, which saves the need for an additional `std::make_pair` call. So I have a slight preference for using `std::__copy`. Please let me know if you have a different thought on this.
https://github.com/llvm/llvm-project/pull/121109
More information about the libcxx-commits
mailing list