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
2329template <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
3337template <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
0 commit comments