1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___ALGORITHM_SET_DIFFERENCE_H 10 #define _LIBCPP___ALGORITHM_SET_DIFFERENCE_H 11 12 #include <__algorithm/comp.h> 13 #include <__algorithm/comp_ref_type.h> 14 #include <__algorithm/copy.h> 15 #include <__config> 16 #include <__functional/identity.h> 17 #include <__functional/invoke.h> 18 #include <__iterator/iterator_traits.h> 19 #include <__utility/move.h> 20 #include <__utility/pair.h> 21 #include <type_traits> 22 23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 24 # pragma GCC system_header 25 #endif 26 27 _LIBCPP_BEGIN_NAMESPACE_STD 28 29 template < class _Comp, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter> 30 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 pair<__uncvref_t<_InIter1>, __uncvref_t<_OutIter> > 31 __set_difference( 32 _InIter1&& __first1, _Sent1&& __last1, _InIter2&& __first2, _Sent2&& __last2, _OutIter&& __result, _Comp&& __comp) { 33 while (__first1 != __last1 && __first2 != __last2) { 34 if (__comp(*__first1, *__first2)) { 35 *__result = *__first1; 36 ++__first1; 37 ++__result; 38 } else if (__comp(*__first2, *__first1)) { 39 ++__first2; 40 } else { 41 ++__first1; 42 ++__first2; 43 } 44 } 45 return std::__copy(std::move(__first1), std::move(__last1), std::move(__result)); 46 } 47 48 template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare> 49 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_difference( 50 _InputIterator1 __first1, 51 _InputIterator1 __last1, 52 _InputIterator2 __first2, 53 _InputIterator2 __last2, 54 _OutputIterator __result, 55 _Compare __comp) { 56 typedef typename __comp_ref_type<_Compare>::type _Comp_ref; 57 return std::__set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp).second; 58 } 59 60 template <class _InputIterator1, class _InputIterator2, class _OutputIterator> 61 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_difference( 62 _InputIterator1 __first1, 63 _InputIterator1 __last1, 64 _InputIterator2 __first2, 65 _InputIterator2 __last2, 66 _OutputIterator __result) { 67 return std::__set_difference( 68 __first1, 69 __last1, 70 __first2, 71 __last2, 72 __result, 73 __less<typename iterator_traits<_InputIterator1>::value_type, 74 typename iterator_traits<_InputIterator2>::value_type>()).second; 75 } 76 77 _LIBCPP_END_NAMESPACE_STD 78 79 #endif // _LIBCPP___ALGORITHM_SET_DIFFERENCE_H 80