is_partitioned.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef _LIBCPP___ALGORITHM_IS_PARTITIONED_H
  9. #define _LIBCPP___ALGORITHM_IS_PARTITIONED_H
  10. #include <__config>
  11. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  12. # pragma GCC system_header
  13. #endif
  14. _LIBCPP_BEGIN_NAMESPACE_STD
  15. template <class _InputIterator, class _Predicate>
  16. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool
  17. is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
  18. for (; __first != __last; ++__first)
  19. if (!__pred(*__first))
  20. break;
  21. if (__first == __last)
  22. return true;
  23. ++__first;
  24. for (; __first != __last; ++__first)
  25. if (__pred(*__first))
  26. return false;
  27. return true;
  28. }
  29. _LIBCPP_END_NAMESPACE_STD
  30. #endif // _LIBCPP___ALGORITHM_IS_PARTITIONED_H