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