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 9 #ifndef _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H 10 #define _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H 11 12 #include <__algorithm/in_found_result.h> 13 #include <__algorithm/iterator_operations.h> 14 #include <__algorithm/make_projected.h> 15 #include <__algorithm/prev_permutation.h> 16 #include <__config> 17 #include <__functional/identity.h> 18 #include <__functional/ranges_operations.h> 19 #include <__iterator/concepts.h> 20 #include <__iterator/sortable.h> 21 #include <__ranges/access.h> 22 #include <__ranges/concepts.h> 23 #include <__ranges/dangling.h> 24 #include <__utility/move.h> 25 26 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 27 # pragma GCC system_header 28 #endif 29 30 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 31 32 _LIBCPP_BEGIN_NAMESPACE_STD 33 34 namespace ranges { 35 36 template <class _InIter> 37 using prev_permutation_result = in_found_result<_InIter>; 38 39 namespace __prev_permutation { 40 41 struct __fn { 42 43 template <bidirectional_iterator _Iter, sentinel_for<_Iter> _Sent, 44 class _Comp = ranges::less, class _Proj = identity> 45 requires sortable<_Iter, _Comp, _Proj> 46 _LIBCPP_HIDE_FROM_ABI constexpr prev_permutation_result<_Iter> 47 operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const { 48 auto __result = std::__prev_permutation<_RangeAlgPolicy>( 49 std::move(__first), std::move(__last), std::__make_projected(__comp, __proj)); 50 return {std::move(__result.first), std::move(__result.second)}; 51 } 52 53 template <bidirectional_range _Range, 54 class _Comp = ranges::less, class _Proj = identity> 55 requires sortable<iterator_t<_Range>, _Comp, _Proj> 56 _LIBCPP_HIDE_FROM_ABI constexpr prev_permutation_result<borrowed_iterator_t<_Range>> 57 operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const { 58 auto __result = std::__prev_permutation<_RangeAlgPolicy>( 59 ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj)); 60 return {std::move(__result.first), std::move(__result.second)}; 61 } 62 63 }; 64 65 } // namespace __prev_permutation 66 67 inline namespace __cpo { 68 constexpr inline auto prev_permutation = __prev_permutation::__fn{}; 69 } // namespace __cpo 70 } // namespace ranges 71 72 _LIBCPP_END_NAMESPACE_STD 73 74 #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 75 76 #endif // _LIBCPP___ALGORITHM_RANGES_PREV_PERMUTATION_H 77