[libcxx-commits] [libcxx] [libcxx] Modify `std::__for_each{, _n}` to accept r-values in `__f` (PR #179451)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 3 05:00:22 PST 2026
================
@@ -17,32 +17,36 @@
#include <__iterator/segmented_iterator.h>
#include <__type_traits/invoke.h>
#include <__type_traits/is_same.h>
+#include <__utility/forward.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _InputIterator, class _Sent, class _Func, class _Proj>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
-__for_each(_InputIterator __first, _Sent __last, _Func& __func, _Proj& __proj) {
+__for_each(_InputIterator __first, _Sent __last, _Func&& __f, _Proj& __proj) {
#ifndef _LIBCPP_CXX03_LANG
if constexpr (using _SpecialAlg =
__specialized_algorithm<_Algorithm::__for_each, __iterator_pair<_InputIterator, _Sent>>;
_SpecialAlg::__has_algorithm) {
- _SpecialAlg()(__first, __last, __func, __proj);
+ _SpecialAlg()(__first, __last, std::forward<_Func>(__f), __proj);
----------------
philnik777 wrote:
I don't think we need to forward here. We're also missing test coverage if the CI is happy, since `_SpecialAlg` doesn't currently accept non-lref arguments.
https://github.com/llvm/llvm-project/pull/179451
More information about the libcxx-commits
mailing list