Skip to content

Commit f1e883f

Browse files
committed
use std::forward
1 parent bb58a98 commit f1e883f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

libcxx/docs/ReleaseNotes/22.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Improvements and New Features
6767
reduced debug information.
6868

6969
- The performance of ``std::find`` has been improved by up to 2x for integral types
70+
- The ``std::generate`` algorithm has been optimized for segmented iterators, resulting in a performance improvement for
71+
``std::deque<short>`` and ``std::join_view<vector<vector<short>>>`` iterators.
7072

7173
Deprecations and Removals
7274
-------------------------

libcxx/include/__algorithm/generate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <__algorithm/for_each.h>
1313
#include <__config>
14+
#include <__utility/forward.h>
1415

1516
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1617
# pragma GCC system_header
@@ -21,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2122
template <class _ForwardIterator, class _Generator>
2223
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
2324
generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) {
24-
std::for_each(__first, __last, [&](auto& __element) { __element = __gen(); });
25+
std::for_each(__first, __last, [&](auto&& __element) { std::forward<decltype(__element)>(__element) = __gen(); });
2526
}
2627

2728
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)