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