Skip to content

Commit b4d752e

Browse files
committed
[libc++] Use forward referencing for predicates, projections, and comparators
1 parent 4775e6d commit b4d752e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+136
-99
lines changed

libcxx/include/__algorithm/adjacent_find.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2727

2828
template <class _Iter, class _Sent, class _Pred, class _Proj>
2929
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Iter
30-
__adjacent_find(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
30+
__adjacent_find(_Iter __first, _Sent __last, _Pred&& __pred, _Proj&& __proj) {
3131
if (__first == __last)
3232
return __first;
3333

libcxx/include/__algorithm/all_of.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222

2323
template <class _Iter, class _Sent, class _Proj, class _Pred>
2424
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
25-
__all_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
25+
__all_of(_Iter __first, _Sent __last, _Pred&& __pred, _Proj&& __proj) {
2626
for (; __first != __last; ++__first) {
2727
if (!std::__invoke(__pred, std::__invoke(__proj, *__first)))
2828
return false;

libcxx/include/__algorithm/any_of.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2222

2323
template <class _Iter, class _Sent, class _Proj, class _Pred>
2424
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
25-
__any_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
25+
__any_of(_Iter __first, _Sent __last, _Pred&& __pred, _Proj&& __proj) {
2626
for (; __first != __last; ++__first) {
2727
if (std::__invoke(__pred, std::__invoke(__proj, *__first)))
2828
return true;

libcxx/include/__algorithm/copy_if.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626

2727
template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred>
2828
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_InIter, _OutIter>
29-
__copy_if(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
29+
__copy_if(_InIter __first, _Sent __last, _OutIter __result, _Pred&& __pred, _Proj&& __proj) {
3030
for (; __first != __last; ++__first) {
3131
if (std::__invoke(__pred, std::__invoke(__proj, *__first))) {
3232
*__result = *__first;

libcxx/include/__algorithm/count.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
3333
// generic implementation
3434
template <class _AlgPolicy, class _Iter, class _Sent, class _Tp, class _Proj>
3535
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 typename _IterOps<_AlgPolicy>::template __difference_type<_Iter>
36-
__count(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
36+
__count(_Iter __first, _Sent __last, const _Tp& __value, _Proj&& __proj) {
3737
typename _IterOps<_AlgPolicy>::template __difference_type<_Iter> __r(0);
3838
for (; __first != __last; ++__first)
3939
if (std::__invoke(__proj, *__first) == __value)

libcxx/include/__algorithm/count_if.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424

2525
template <class _AlgPolicy, class _Iter, class _Sent, class _Proj, class _Pred>
2626
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __policy_iter_diff_t<_AlgPolicy, _Iter>
27-
__count_if(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
27+
__count_if(_Iter __first, _Sent __last, _Pred&& __pred, _Proj&& __proj) {
2828
__policy_iter_diff_t<_AlgPolicy, _Iter> __counter(0);
2929
for (; __first != __last; ++__first) {
3030
if (std::__invoke(__pred, std::__invoke(__proj, *__first)))

libcxx/include/__algorithm/equal.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,13 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
208208

209209
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
210210
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl(
211-
_Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred& __comp, _Proj1& __proj1, _Proj2& __proj2) {
211+
_Iter1 __first1,
212+
_Sent1 __last1,
213+
_Iter2 __first2,
214+
_Sent2 __last2,
215+
_Pred&& __comp,
216+
_Proj1&& __proj1,
217+
_Proj2&& __proj2) {
212218
while (__first1 != __last1 && __first2 != __last2) {
213219
if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
214220
return false;
@@ -228,7 +234,7 @@ template <class _Tp,
228234
__libcpp_is_trivially_equality_comparable<_Tp, _Up>::value,
229235
int> = 0>
230236
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
231-
__equal_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&, _Proj2&) {
237+
__equal_impl(_Tp* __first1, _Tp* __last1, _Up* __first2, _Up*, _Pred&, _Proj1&&, _Proj2&&) {
232238
return std::__constexpr_memcmp_equal(__first1, __first2, __element_count(__last1 - __first1));
233239
}
234240

libcxx/include/__algorithm/find.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
4444
// generic implementation
4545
template <class _Iter, class _Sent, class _Tp, class _Proj>
4646
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Iter
47-
__find(_Iter __first, _Sent __last, const _Tp& __value, _Proj& __proj) {
47+
__find(_Iter __first, _Sent __last, const _Tp& __value, _Proj&& __proj) {
4848
for (; __first != __last; ++__first)
4949
if (std::__invoke(__proj, *__first) == __value)
5050
break;
@@ -88,7 +88,7 @@ template <class _Tp,
8888
is_signed<_Tp>::value == is_signed<_Up>::value,
8989
int> = 0>
9090
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Tp*
91-
__find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj& __proj) {
91+
__find(_Tp* __first, _Tp* __last, const _Up& __value, _Proj&& __proj) {
9292
if (__value < numeric_limits<_Tp>::min() || __value > numeric_limits<_Tp>::max())
9393
return __last;
9494
return std::__find(__first, __last, _Tp(__value), __proj);
@@ -151,7 +151,7 @@ template <class _SegmentedIterator,
151151
class _Proj,
152152
__enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0>
153153
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator
154-
__find(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value, _Proj& __proj) {
154+
__find(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value, _Proj&& __proj) {
155155
return std::__find_segment_if(std::move(__first), std::move(__last), __find_segment<_Tp>(__value), __proj);
156156
}
157157

libcxx/include/__algorithm/find_end.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1>
3737
_Sent1 __last1,
3838
_Iter2 __first2,
3939
_Sent2 __last2,
40-
_Pred& __pred,
41-
_Proj1& __proj1,
42-
_Proj2& __proj2,
40+
_Pred&& __pred,
41+
_Proj1&& __proj1,
42+
_Proj2&& __proj2,
4343
forward_iterator_tag,
4444
forward_iterator_tag) {
4545
// modeled after search algorithm

libcxx/include/__algorithm/find_segment_if.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2626

2727
template <class _SegmentedIterator, class _Pred, class _Proj>
2828
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator
29-
__find_segment_if(_SegmentedIterator __first, _SegmentedIterator __last, _Pred __pred, _Proj& __proj) {
29+
__find_segment_if(_SegmentedIterator __first, _SegmentedIterator __last, _Pred __pred, _Proj&& __proj) {
3030
using _Traits = __segmented_iterator_traits<_SegmentedIterator>;
3131

3232
auto __sfirst = _Traits::__segment(__first);

0 commit comments

Comments
 (0)