Skip to content

Commit 92250df

Browse files
committed
[libc++] Forward std::all_of and std::none_of to std::all_of
1 parent 4ecfaa6 commit 92250df

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

libcxx/include/__algorithm/all_of.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@
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/forward.h>
18+
#include <__utility/move.h>
1619

1720
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1821
# pragma GCC system_header
1922
#endif
2023

24+
_LIBCPP_PUSH_MACROS
25+
#include <__undef_macros>
26+
2127
_LIBCPP_BEGIN_NAMESPACE_STD
2228

2329
template <class _Iter, class _Sent, class _Proj, class _Pred>
2430
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
2531
__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;
32+
using _Ref = decltype(std::__invoke(__proj, *__first));
33+
auto __negated_pred = [&__pred](_Ref __arg) -> bool { return !std::__invoke(__pred, std::forward<_Ref>(__arg)); };
34+
return !std::__any_of(std::move(__first), std::move(__last), __negated_pred, __proj);
3135
}
3236

3337
template <class _InputIterator, class _Predicate>
@@ -39,4 +43,6 @@ all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
3943

4044
_LIBCPP_END_NAMESPACE_STD
4145

46+
_LIBCPP_POP_MACROS
47+
4248
#endif // _LIBCPP___ALGORITHM_ALL_OF_H

libcxx/include/__algorithm/none_of.h

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

13+
#include <__algorithm/any_of.h>
1314
#include <__config>
15+
#include <__functional/identity.h>
1416

1517
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
1618
# pragma GCC system_header
@@ -21,10 +23,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2123
template <class _InputIterator, class _Predicate>
2224
[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
2325
none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
24-
for (; __first != __last; ++__first)
25-
if (__pred(*__first))
26-
return false;
27-
return true;
26+
__identity __proj;
27+
return !std::__any_of(__first, __last, __pred, __proj);
2828
}
2929

3030
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)