Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:18

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_PARTITION_H
0010 #define _LIBCPP___CXX03___ALGORITHM_PARTITION_H
0011 
0012 #include <__cxx03/__algorithm/iterator_operations.h>
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__iterator/iterator_traits.h>
0015 #include <__cxx03/__utility/move.h>
0016 #include <__cxx03/__utility/pair.h>
0017 
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 #  pragma GCC system_header
0020 #endif
0021 
0022 _LIBCPP_PUSH_MACROS
0023 #include <__cxx03/__undef_macros>
0024 
0025 _LIBCPP_BEGIN_NAMESPACE_STD
0026 
0027 template <class _Predicate, class _AlgPolicy, class _ForwardIterator, class _Sentinel>
0028 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
0029 __partition_impl(_ForwardIterator __first, _Sentinel __last, _Predicate __pred, forward_iterator_tag) {
0030   while (true) {
0031     if (__first == __last)
0032       return std::make_pair(std::move(__first), std::move(__first));
0033     if (!__pred(*__first))
0034       break;
0035     ++__first;
0036   }
0037 
0038   _ForwardIterator __p = __first;
0039   while (++__p != __last) {
0040     if (__pred(*__p)) {
0041       _IterOps<_AlgPolicy>::iter_swap(__first, __p);
0042       ++__first;
0043     }
0044   }
0045   return std::make_pair(std::move(__first), std::move(__p));
0046 }
0047 
0048 template <class _Predicate, class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
0049 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_BidirectionalIterator, _BidirectionalIterator>
0050 __partition_impl(_BidirectionalIterator __first, _Sentinel __sentinel, _Predicate __pred, bidirectional_iterator_tag) {
0051   _BidirectionalIterator __original_last = _IterOps<_AlgPolicy>::next(__first, __sentinel);
0052   _BidirectionalIterator __last          = __original_last;
0053 
0054   while (true) {
0055     while (true) {
0056       if (__first == __last)
0057         return std::make_pair(std::move(__first), std::move(__original_last));
0058       if (!__pred(*__first))
0059         break;
0060       ++__first;
0061     }
0062     do {
0063       if (__first == --__last)
0064         return std::make_pair(std::move(__first), std::move(__original_last));
0065     } while (!__pred(*__last));
0066     _IterOps<_AlgPolicy>::iter_swap(__first, __last);
0067     ++__first;
0068   }
0069 }
0070 
0071 template <class _AlgPolicy, class _ForwardIterator, class _Sentinel, class _Predicate, class _IterCategory>
0072 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_ForwardIterator, _ForwardIterator>
0073 __partition(_ForwardIterator __first, _Sentinel __last, _Predicate&& __pred, _IterCategory __iter_category) {
0074   return std::__partition_impl<__remove_cvref_t<_Predicate>&, _AlgPolicy>(
0075       std::move(__first), std::move(__last), __pred, __iter_category);
0076 }
0077 
0078 template <class _ForwardIterator, class _Predicate>
0079 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
0080 partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
0081   using _IterCategory = typename iterator_traits<_ForwardIterator>::iterator_category;
0082   auto __result = std::__partition<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred, _IterCategory());
0083   return __result.first;
0084 }
0085 
0086 _LIBCPP_END_NAMESPACE_STD
0087 
0088 _LIBCPP_POP_MACROS
0089 
0090 #endif // _LIBCPP___CXX03___ALGORITHM_PARTITION_H