[libcxx-commits] [libcxx] [libc++] Use forwarding refs for predicates and projections in algorithms helpers (PR #133097)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Mar 26 07:44:21 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 4775e6d9099467df9363e1a3cd5950cc3d2fde05 34f4e03b09ebcb339c93adab4cdedb8cf824115e --extensions h -- libcxx/include/__algorithm/adjacent_find.h libcxx/include/__algorithm/all_of.h libcxx/include/__algorithm/any_of.h libcxx/include/__algorithm/copy_if.h libcxx/include/__algorithm/count.h libcxx/include/__algorithm/count_if.h libcxx/include/__algorithm/equal.h libcxx/include/__algorithm/find.h libcxx/include/__algorithm/find_end.h libcxx/include/__algorithm/find_segment_if.h libcxx/include/__algorithm/lexicographical_compare.h libcxx/include/__algorithm/lower_bound.h libcxx/include/__algorithm/make_projected.h libcxx/include/__algorithm/min_element.h libcxx/include/__algorithm/minmax_element.h libcxx/include/__algorithm/mismatch.h libcxx/include/__algorithm/ranges_ends_with.h libcxx/include/__algorithm/ranges_find.h libcxx/include/__algorithm/ranges_find_first_of.h libcxx/include/__algorithm/ranges_find_if.h libcxx/include/__algorithm/ranges_find_last.h libcxx/include/__algorithm/ranges_for_each.h libcxx/include/__algorithm/ranges_is_heap.h libcxx/include/__algorithm/ranges_is_heap_until.h libcxx/include/__algorithm/ranges_is_partitioned.h libcxx/include/__algorithm/ranges_is_permutation.h libcxx/include/__algorithm/ranges_is_sorted_until.h libcxx/include/__algorithm/ranges_lexicographical_compare.h libcxx/include/__algorithm/ranges_make_heap.h libcxx/include/__algorithm/ranges_min_element.h libcxx/include/__algorithm/ranges_mismatch.h libcxx/include/__algorithm/ranges_none_of.h libcxx/include/__algorithm/ranges_nth_element.h libcxx/include/__algorithm/ranges_partial_sort.h libcxx/include/__algorithm/ranges_partition_copy.h libcxx/include/__algorithm/ranges_partition_point.h libcxx/include/__algorithm/ranges_pop_heap.h libcxx/include/__algorithm/ranges_push_heap.h libcxx/include/__algorithm/ranges_remove_copy_if.h libcxx/include/__algorithm/ranges_remove_if.h libcxx/include/__algorithm/ranges_replace_copy_if.h libcxx/include/__algorithm/ranges_replace_if.h libcxx/include/__algorithm/ranges_search.h libcxx/include/__algorithm/ranges_search_n.h libcxx/include/__algorithm/ranges_sort.h libcxx/include/__algorithm/ranges_sort_heap.h libcxx/include/__algorithm/ranges_stable_sort.h libcxx/include/__algorithm/ranges_transform.h libcxx/include/__algorithm/search.h libcxx/include/__algorithm/search_n.h libcxx/include/__algorithm/sort.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/include/__algorithm/equal.h b/libcxx/include/__algorithm/equal.h
index a73167df49..8b922c1b4a 100644
--- a/libcxx/include/__algorithm/equal.h
+++ b/libcxx/include/__algorithm/equal.h
@@ -208,7 +208,13 @@ equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __equal_impl(
- _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) {
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred&& __comp,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
while (__first1 != __last1 && __first2 != __last2) {
if (!std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
return false;
diff --git a/libcxx/include/__algorithm/lexicographical_compare.h b/libcxx/include/__algorithm/lexicographical_compare.h
index 03b1ed3407..0467cdcfb4 100644
--- a/libcxx/include/__algorithm/lexicographical_compare.h
+++ b/libcxx/include/__algorithm/lexicographical_compare.h
@@ -41,7 +41,13 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Proj1, class _Proj2, class _Comp>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __lexicographical_compare(
- _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Comp&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) {
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Comp&& __comp,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
while (__first2 != __last2) {
if (__first1 == __last1 ||
std::__invoke(__comp, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
diff --git a/libcxx/include/__algorithm/make_projected.h b/libcxx/include/__algorithm/make_projected.h
index c2608c3495..950daf05a4 100644
--- a/libcxx/include/__algorithm/make_projected.h
+++ b/libcxx/include/__algorithm/make_projected.h
@@ -79,7 +79,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
namespace ranges {
template <class _Comp, class _Proj1, class _Proj2>
-_LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) __make_projected_comp(_Comp&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) {
+_LIBCPP_HIDE_FROM_ABI constexpr decltype(auto)
+__make_projected_comp(_Comp&& __comp, _Proj1&& __proj1, _Proj2&& __proj2) {
if constexpr (__is_identity<decay_t<_Proj1>>::value && __is_identity<decay_t<_Proj2>>::value &&
!is_member_pointer_v<decay_t<_Comp>>) {
// Avoid creating the lambda and just use the pristine comparator -- for certain algorithms, this would enable
diff --git a/libcxx/include/__algorithm/mismatch.h b/libcxx/include/__algorithm/mismatch.h
index 4159946415..cb2aa2e055 100644
--- a/libcxx/include/__algorithm/mismatch.h
+++ b/libcxx/include/__algorithm/mismatch.h
@@ -168,7 +168,13 @@ mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __fi
#if _LIBCPP_STD_VER >= 14
template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, class _Proj1, class _Proj2>
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter1, _Iter2> __mismatch(
- _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred&& __pred,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
while (__first1 != __last1 && __first2 != __last2) {
if (!std::__invoke(__pred, std::__invoke(__proj1, *__first1), std::__invoke(__proj2, *__first2)))
break;
@@ -179,8 +185,8 @@ template <class _Iter1, class _Sent1, class _Iter2, class _Sent2, class _Pred, c
}
template <class _Tp, class _Pred, class _Proj1, class _Proj2>
-[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*>
-__mismatch(_Tp* __first1, _Tp* __last1, _Tp* __first2, _Tp* __last2, _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Tp*, _Tp*> __mismatch(
+ _Tp* __first1, _Tp* __last1, _Tp* __first2, _Tp* __last2, _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
auto __len = std::min(__last1 - __first1, __last2 - __first2);
return std::__mismatch(__first1, __first1 + __len, __first2, __pred, __proj1, __proj2);
}
diff --git a/libcxx/include/__algorithm/search.h b/libcxx/include/__algorithm/search.h
index 5ddd6fa291..da340462d4 100644
--- a/libcxx/include/__algorithm/search.h
+++ b/libcxx/include/__algorithm/search.h
@@ -37,7 +37,13 @@ template <class _AlgPolicy,
class _Proj1,
class _Proj2>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_forward_impl(
- _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred&& __pred,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
if (__first2 == __last2)
return std::make_pair(__first1, __first1); // Everything matches an empty sequence
while (true) {
@@ -128,7 +134,13 @@ template <class _Iter1,
__has_random_access_iterator_category<_Iter2>::value,
int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_impl(
- _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred&& __pred,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
auto __size2 = __last2 - __first2;
if (__size2 == 0)
return std::make_pair(__first1, __first1);
@@ -155,7 +167,13 @@ template <
__has_random_access_iterator_category<_Iter2>::value),
int> = 0>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 pair<_Iter1, _Iter1> __search_impl(
- _Iter1 __first1, _Sent1 __last1, _Iter2 __first2, _Sent2 __last2, _Pred&& __pred, _Proj1&& __proj1, _Proj2&& __proj2) {
+ _Iter1 __first1,
+ _Sent1 __last1,
+ _Iter2 __first2,
+ _Sent2 __last2,
+ _Pred&& __pred,
+ _Proj1&& __proj1,
+ _Proj2&& __proj2) {
return std::__search_forward_impl<_ClassicAlgPolicy>(__first1, __last1, __first2, __last2, __pred, __proj1, __proj2);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/133097
More information about the libcxx-commits
mailing list