File indexing completed on 2026-05-03 08:13:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_SET_UNION_H
0010 #define _LIBCPP___CXX03___ALGORITHM_SET_UNION_H
0011
0012 #include <__cxx03/__algorithm/comp.h>
0013 #include <__cxx03/__algorithm/comp_ref_type.h>
0014 #include <__cxx03/__algorithm/copy.h>
0015 #include <__cxx03/__algorithm/iterator_operations.h>
0016 #include <__cxx03/__config>
0017 #include <__cxx03/__iterator/iterator_traits.h>
0018 #include <__cxx03/__utility/move.h>
0019 #include <__cxx03/__utility/pair.h>
0020
0021 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0022 # pragma GCC system_header
0023 #endif
0024
0025 _LIBCPP_PUSH_MACROS
0026 #include <__cxx03/__undef_macros>
0027
0028 _LIBCPP_BEGIN_NAMESPACE_STD
0029
0030 template <class _InIter1, class _InIter2, class _OutIter>
0031 struct __set_union_result {
0032 _InIter1 __in1_;
0033 _InIter2 __in2_;
0034 _OutIter __out_;
0035
0036
0037 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0038 __set_union_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter)
0039 : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {}
0040 };
0041
0042 template <class _AlgPolicy, class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
0043 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result<_InIter1, _InIter2, _OutIter> __set_union(
0044 _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) {
0045 for (; __first1 != __last1; ++__result) {
0046 if (__first2 == __last2) {
0047 auto __ret1 = std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result));
0048 return __set_union_result<_InIter1, _InIter2, _OutIter>(
0049 std::move(__ret1.first), std::move(__first2), std::move((__ret1.second)));
0050 }
0051 if (__comp(*__first2, *__first1)) {
0052 *__result = *__first2;
0053 ++__first2;
0054 } else {
0055 if (!__comp(*__first1, *__first2)) {
0056 ++__first2;
0057 }
0058 *__result = *__first1;
0059 ++__first1;
0060 }
0061 }
0062 auto __ret2 = std::__copy<_AlgPolicy>(std::move(__first2), std::move(__last2), std::move(__result));
0063 return __set_union_result<_InIter1, _InIter2, _OutIter>(
0064 std::move(__first1), std::move(__ret2.first), std::move((__ret2.second)));
0065 }
0066
0067 template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
0068 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union(
0069 _InputIterator1 __first1,
0070 _InputIterator1 __last1,
0071 _InputIterator2 __first2,
0072 _InputIterator2 __last2,
0073 _OutputIterator __result,
0074 _Compare __comp) {
0075 return std::__set_union<_ClassicAlgPolicy, __comp_ref_type<_Compare> >(
0076 std::move(__first1),
0077 std::move(__last1),
0078 std::move(__first2),
0079 std::move(__last2),
0080 std::move(__result),
0081 __comp)
0082 .__out_;
0083 }
0084
0085 template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
0086 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union(
0087 _InputIterator1 __first1,
0088 _InputIterator1 __last1,
0089 _InputIterator2 __first2,
0090 _InputIterator2 __last2,
0091 _OutputIterator __result) {
0092 return std::set_union(
0093 std::move(__first1),
0094 std::move(__last1),
0095 std::move(__first2),
0096 std::move(__last2),
0097 std::move(__result),
0098 __less<>());
0099 }
0100
0101 _LIBCPP_END_NAMESPACE_STD
0102
0103 _LIBCPP_POP_MACROS
0104
0105 #endif