Back to home page

EIC code displayed by LXR

 
 

    


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

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___CXX03___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H
0010 #define _LIBCPP___CXX03___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_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_symmetric_difference_result {
0032   _InIter1 __in1_;
0033   _InIter2 __in2_;
0034   _OutIter __out_;
0035 
0036   // need a constructor as C++03 aggregate init is hard
0037   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0038   __set_symmetric_difference_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_symmetric_difference_result<_InIter1, _InIter2, _OutIter>
0044 __set_symmetric_difference(
0045     _InIter1 __first1, _Sent1 __last1, _InIter2 __first2, _Sent2 __last2, _OutIter __result, _Compare&& __comp) {
0046   while (__first1 != __last1) {
0047     if (__first2 == __last2) {
0048       auto __ret1 = std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result));
0049       return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>(
0050           std::move(__ret1.first), std::move(__first2), std::move((__ret1.second)));
0051     }
0052     if (__comp(*__first1, *__first2)) {
0053       *__result = *__first1;
0054       ++__result;
0055       ++__first1;
0056     } else {
0057       if (__comp(*__first2, *__first1)) {
0058         *__result = *__first2;
0059         ++__result;
0060       } else {
0061         ++__first1;
0062       }
0063       ++__first2;
0064     }
0065   }
0066   auto __ret2 = std::__copy<_AlgPolicy>(std::move(__first2), std::move(__last2), std::move(__result));
0067   return __set_symmetric_difference_result<_InIter1, _InIter2, _OutIter>(
0068       std::move(__first1), std::move(__ret2.first), std::move((__ret2.second)));
0069 }
0070 
0071 template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
0072 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_symmetric_difference(
0073     _InputIterator1 __first1,
0074     _InputIterator1 __last1,
0075     _InputIterator2 __first2,
0076     _InputIterator2 __last2,
0077     _OutputIterator __result,
0078     _Compare __comp) {
0079   return std::__set_symmetric_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >(
0080              std::move(__first1),
0081              std::move(__last1),
0082              std::move(__first2),
0083              std::move(__last2),
0084              std::move(__result),
0085              __comp)
0086       .__out_;
0087 }
0088 
0089 template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
0090 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator set_symmetric_difference(
0091     _InputIterator1 __first1,
0092     _InputIterator1 __last1,
0093     _InputIterator2 __first2,
0094     _InputIterator2 __last2,
0095     _OutputIterator __result) {
0096   return std::set_symmetric_difference(
0097       std::move(__first1),
0098       std::move(__last1),
0099       std::move(__first2),
0100       std::move(__last2),
0101       std::move(__result),
0102       __less<>());
0103 }
0104 
0105 _LIBCPP_END_NAMESPACE_STD
0106 
0107 _LIBCPP_POP_MACROS
0108 
0109 #endif // _LIBCPP___CXX03___ALGORITHM_SET_SYMMETRIC_DIFFERENCE_H