1753f127fSDimitry Andric //===----------------------------------------------------------------------===// 2753f127fSDimitry Andric // 3753f127fSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4753f127fSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5753f127fSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6753f127fSDimitry Andric // 7753f127fSDimitry Andric //===----------------------------------------------------------------------===// 8753f127fSDimitry Andric 9753f127fSDimitry Andric #ifndef _LIBCPP___ALGORITHM_RANGES_PARTITION_H 10753f127fSDimitry Andric #define _LIBCPP___ALGORITHM_RANGES_PARTITION_H 11753f127fSDimitry Andric 12fcaf7f86SDimitry Andric #include <__algorithm/iterator_operations.h> 13753f127fSDimitry Andric #include <__algorithm/make_projected.h> 14753f127fSDimitry Andric #include <__algorithm/partition.h> 15fcaf7f86SDimitry Andric #include <__algorithm/ranges_iterator_concept.h> 16753f127fSDimitry Andric #include <__config> 17753f127fSDimitry Andric #include <__functional/identity.h> 18753f127fSDimitry Andric #include <__functional/invoke.h> 19753f127fSDimitry Andric #include <__functional/ranges_operations.h> 20753f127fSDimitry Andric #include <__iterator/concepts.h> 21753f127fSDimitry Andric #include <__iterator/iterator_traits.h> 22753f127fSDimitry Andric #include <__iterator/permutable.h> 23753f127fSDimitry Andric #include <__iterator/projected.h> 24753f127fSDimitry Andric #include <__ranges/access.h> 25753f127fSDimitry Andric #include <__ranges/concepts.h> 26753f127fSDimitry Andric #include <__ranges/subrange.h> 27753f127fSDimitry Andric #include <__utility/forward.h> 28753f127fSDimitry Andric #include <__utility/move.h> 29bdd1243dSDimitry Andric #include <__utility/pair.h> 30753f127fSDimitry Andric 31753f127fSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 32753f127fSDimitry Andric # pragma GCC system_header 33753f127fSDimitry Andric #endif 34753f127fSDimitry Andric 35*b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS 36*b3edf446SDimitry Andric #include <__undef_macros> 37*b3edf446SDimitry Andric 3806c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20 39753f127fSDimitry Andric 40753f127fSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 41753f127fSDimitry Andric 42753f127fSDimitry Andric namespace ranges { 43753f127fSDimitry Andric namespace __partition { 44753f127fSDimitry Andric 45753f127fSDimitry Andric struct __fn { 46fcaf7f86SDimitry Andric template <class _Iter, class _Sent, class _Proj, class _Pred> 4706c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI static constexpr subrange<__remove_cvref_t<_Iter>> 4806c3fb27SDimitry Andric __partition_fn_impl(_Iter&& __first, _Sent&& __last, _Pred&& __pred, _Proj&& __proj) { 4961cfbce3SDimitry Andric auto&& __projected_pred = std::__make_projected(__pred, __proj); 50fcaf7f86SDimitry Andric auto __result = std::__partition<_RangeAlgPolicy>( 51fcaf7f86SDimitry Andric std::move(__first), std::move(__last), __projected_pred, __iterator_concept<_Iter>()); 52fcaf7f86SDimitry Andric 53fcaf7f86SDimitry Andric return {std::move(__result.first), std::move(__result.second)}; 54fcaf7f86SDimitry Andric } 55fcaf7f86SDimitry Andric 5606c3fb27SDimitry Andric template <permutable _Iter, 5706c3fb27SDimitry Andric sentinel_for<_Iter> _Sent, 5806c3fb27SDimitry Andric class _Proj = identity, 59753f127fSDimitry Andric indirect_unary_predicate<projected<_Iter, _Proj>> _Pred> 6006c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter> 6106c3fb27SDimitry Andric operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const { 62fcaf7f86SDimitry Andric return __partition_fn_impl(__first, __last, __pred, __proj); 63753f127fSDimitry Andric } 64753f127fSDimitry Andric 6506c3fb27SDimitry Andric template <forward_range _Range, 6606c3fb27SDimitry Andric class _Proj = identity, 67753f127fSDimitry Andric indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred> 68753f127fSDimitry Andric requires permutable<iterator_t<_Range>> 6906c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range> 7006c3fb27SDimitry Andric operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const { 71fcaf7f86SDimitry Andric return __partition_fn_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj); 72753f127fSDimitry Andric } 73753f127fSDimitry Andric }; 74753f127fSDimitry Andric 75753f127fSDimitry Andric } // namespace __partition 76753f127fSDimitry Andric 77753f127fSDimitry Andric inline namespace __cpo { 78753f127fSDimitry Andric inline constexpr auto partition = __partition::__fn{}; 79753f127fSDimitry Andric } // namespace __cpo 80753f127fSDimitry Andric } // namespace ranges 81753f127fSDimitry Andric 82753f127fSDimitry Andric _LIBCPP_END_NAMESPACE_STD 83753f127fSDimitry Andric 8406c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20 85753f127fSDimitry Andric 86*b3edf446SDimitry Andric _LIBCPP_POP_MACROS 87*b3edf446SDimitry Andric 88753f127fSDimitry Andric #endif // _LIBCPP___ALGORITHM_RANGES_PARTITION_H 89