File indexing completed on 2026-05-03 08:13:08
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___ALGORITHM_MERGE_H
0010 #define _LIBCPP___ALGORITHM_MERGE_H
0011
0012 #include <__algorithm/comp.h>
0013 #include <__algorithm/comp_ref_type.h>
0014 #include <__algorithm/copy.h>
0015 #include <__config>
0016
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 # pragma GCC system_header
0019 #endif
0020
0021 _LIBCPP_BEGIN_NAMESPACE_STD
0022
0023 template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
0024 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator __merge(
0025 _InputIterator1 __first1,
0026 _InputIterator1 __last1,
0027 _InputIterator2 __first2,
0028 _InputIterator2 __last2,
0029 _OutputIterator __result,
0030 _Compare __comp) {
0031 for (; __first1 != __last1; ++__result) {
0032 if (__first2 == __last2)
0033 return std::copy(__first1, __last1, __result);
0034 if (__comp(*__first2, *__first1)) {
0035 *__result = *__first2;
0036 ++__first2;
0037 } else {
0038 *__result = *__first1;
0039 ++__first1;
0040 }
0041 }
0042 return std::copy(__first2, __last2, __result);
0043 }
0044
0045 template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
0046 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0047 merge(_InputIterator1 __first1,
0048 _InputIterator1 __last1,
0049 _InputIterator2 __first2,
0050 _InputIterator2 __last2,
0051 _OutputIterator __result,
0052 _Compare __comp) {
0053 return std::__merge<__comp_ref_type<_Compare> >(__first1, __last1, __first2, __last2, __result, __comp);
0054 }
0055
0056 template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
0057 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
0058 merge(_InputIterator1 __first1,
0059 _InputIterator1 __last1,
0060 _InputIterator2 __first2,
0061 _InputIterator2 __last2,
0062 _OutputIterator __result) {
0063 return std::merge(__first1, __last1, __first2, __last2, __result, __less<>());
0064 }
0065
0066 _LIBCPP_END_NAMESPACE_STD
0067
0068 #endif