Skip to content

Commit 5ce7acb

Browse files
committed
[libc++] Forward std::all_of and std::none_of to std::all_of
1 parent 577b519 commit 5ce7acb

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

libcxx/include/__algorithm/all_of.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
#ifndef _LIBCPP___ALGORITHM_ALL_OF_H
1111
#define _LIBCPP___ALGORITHM_ALL_OF_H
1212

13+
#include <__algorithm/any_of.h>
1314
#include <__config>
1415
#include <__functional/identity.h>
1516
#include <__type_traits/invoke.h>
17+
#include <__utility/move.h>
1618

1719
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1820
# pragma GCC system_header
@@ -23,11 +25,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2325
template <class _Iter, class _Sent, class _Proj, class _Pred>
2426
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
2527
__all_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
26-
for (; __first != __last; ++__first) {
27-
if (!std::__invoke(__pred, std::__invoke(__proj, *__first)))
28-
return false;
29-
}
30-
return true;
28+
using _Ref = decltype(std::__invoke(__proj, *__first));
29+
return !std::__any_of(
30+
std::move(__first),
31+
std::move(__last),
32+
[&__pred](_Ref __arg) { return !std::__invoke(__pred, std::forward<_Ref>(__arg)); },
33+
__proj);
3134
}
3235

3336
template <class _InputIterator, class _Predicate>

libcxx/include/__algorithm/none_of.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#ifndef _LIBCPP___ALGORITHM_NONE_OF_H
1111
#define _LIBCPP___ALGORITHM_NONE_OF_H
1212

13+
#include <__algorithm/any_of.h>
1314
#include <__config>
1415

1516
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -21,10 +22,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2122
template <class _InputIterator, class _Predicate>
2223
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2324
none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
24-
for (; __first != __last; ++__first)
25-
if (__pred(*__first))
26-
return false;
27-
return true;
25+
return !std::any_of(__first, __last, __pred);
2826
}
2927

3028
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)