Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:12

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___ALGORITHM_SET_UNION_H
0010 #define _LIBCPP___ALGORITHM_SET_UNION_H
0011 
0012 #include <__algorithm/comp.h>
0013 #include <__algorithm/comp_ref_type.h>
0014 #include <__algorithm/copy.h>
0015 #include <__config>
0016 #include <__iterator/iterator_traits.h>
0017 #include <__utility/move.h>
0018 #include <__utility/pair.h>
0019 
0020 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0021 #  pragma GCC system_header
0022 #endif
0023 
0024 _LIBCPP_PUSH_MACROS
0025 #include <__undef_macros>
0026 
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028 
0029 template <class _InIter1, class _InIter2, class _OutIter>
0030 struct __set_union_result {
0031   _InIter1 __in1_;
0032   _InIter2 __in2_;
0033   _OutIter __out_;
0034 
0035   // need a constructor as C++03 aggregate init is hard
0036   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0037   __set_union_result(_InIter1&& __in_iter1, _InIter2&& __in_iter2, _OutIter&& __out_iter)
0038       : __in1_(std::move(__in_iter1)), __in2_(std::move(__in_iter2)), __out_(std::move(__out_iter)) {}
0039 };
0040 
0041 template <class _Compare, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
0042 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __set_union_result<_InIter1, _InIter2, _OutIter> __set_union(
0043     _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) {
0044   for (; __first1 != __last1; ++__result) {
0045     if (__first2 == __last2) {
0046       auto __ret1 = std::__copy(std::move(__first1), std::move(__last1), std::move(__result));
0047       return __set_union_result<_InIter1, _InIter2, _OutIter>(
0048           std::move(__ret1.first), std::move(__first2), std::move((__ret1.second)));
0049     }
0050     if (__comp(*__first2, *__first1)) {
0051       *__result = *__first2;
0052       ++__first2;
0053     } else {
0054       if (!__comp(*__first1, *__first2)) {
0055         ++__first2;
0056       }
0057       *__result = *__first1;
0058       ++__first1;
0059     }
0060   }
0061   auto __ret2 = std::__copy(std::move(__first2), std::move(__last2), std::move(__result));
0062   return __set_union_result<_InIter1, _InIter2, _OutIter>(
0063       std::move(__first1), std::move(__ret2.first), std::move((__ret2.second)));
0064 }
0065 
0066 template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
0067 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union(
0068     _InputIterator1 __first1,
0069     _InputIterator1 __last1,
0070     _InputIterator2 __first2,
0071     _InputIterator2 __last2,
0072     _OutputIterator __result,
0073     _Compare __comp) {
0074   return std::__set_union<__comp_ref_type<_Compare> >(
0075              std::move(__first1),
0076              std::move(__last1),
0077              std::move(__first2),
0078              std::move(__last2),
0079              std::move(__result),
0080              __comp)
0081       .__out_;
0082 }
0083 
0084 template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
0085 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_union(
0086     _InputIterator1 __first1,
0087     _InputIterator1 __last1,
0088     _InputIterator2 __first2,
0089     _InputIterator2 __last2,
0090     _OutputIterator __result) {
0091   return std::set_union(
0092       std::move(__first1),
0093       std::move(__last1),
0094       std::move(__first2),
0095       std::move(__last2),
0096       std::move(__result),
0097       __less<>());
0098 }
0099 
0100 _LIBCPP_END_NAMESPACE_STD
0101 
0102 _LIBCPP_POP_MACROS
0103 
0104 #endif // _LIBCPP___ALGORITHM_SET_UNION_H