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___CXX03___ALGORITHM_SET_DIFFERENCE_H
10 #define _LIBCPP___CXX03___ALGORITHM_SET_DIFFERENCE_H
11
12 #include <__cxx03/__algorithm/comp.h>
13 #include <__cxx03/__algorithm/comp_ref_type.h>
14 #include <__cxx03/__algorithm/copy.h>
15 #include <__cxx03/__algorithm/iterator_operations.h>
16 #include <__cxx03/__config>
17 #include <__cxx03/__functional/identity.h>
18 #include <__cxx03/__iterator/iterator_traits.h>
19 #include <__cxx03/__type_traits/remove_cvref.h>
20 #include <__cxx03/__utility/move.h>
21 #include <__cxx03/__utility/pair.h>
22
23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24 # pragma GCC system_header
25 #endif
26
27 _LIBCPP_PUSH_MACROS
28 #include <__cxx03/__undef_macros>
29
30 _LIBCPP_BEGIN_NAMESPACE_STD
31
32 template <class _AlgPolicy, class _Comp, class _InIter1, class _Sent1, class _InIter2, class _Sent2, class _OutIter>
__set_difference(_InIter1 && __first1,_Sent1 && __last1,_InIter2 && __first2,_Sent2 && __last2,_OutIter && __result,_Comp && __comp)33 _LIBCPP_HIDE_FROM_ABI pair<__remove_cvref_t<_InIter1>, __remove_cvref_t<_OutIter> > __set_difference(
34 _InIter1&& __first1, _Sent1&& __last1, _InIter2&& __first2, _Sent2&& __last2, _OutIter&& __result, _Comp&& __comp) {
35 while (__first1 != __last1 && __first2 != __last2) {
36 if (__comp(*__first1, *__first2)) {
37 *__result = *__first1;
38 ++__first1;
39 ++__result;
40 } else if (__comp(*__first2, *__first1)) {
41 ++__first2;
42 } else {
43 ++__first1;
44 ++__first2;
45 }
46 }
47 return std::__copy<_AlgPolicy>(std::move(__first1), std::move(__last1), std::move(__result));
48 }
49
50 template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
set_difference(_InputIterator1 __first1,_InputIterator1 __last1,_InputIterator2 __first2,_InputIterator2 __last2,_OutputIterator __result,_Compare __comp)51 inline _LIBCPP_HIDE_FROM_ABI _OutputIterator set_difference(
52 _InputIterator1 __first1,
53 _InputIterator1 __last1,
54 _InputIterator2 __first2,
55 _InputIterator2 __last2,
56 _OutputIterator __result,
57 _Compare __comp) {
58 return std::__set_difference<_ClassicAlgPolicy, __comp_ref_type<_Compare> >(
59 __first1, __last1, __first2, __last2, __result, __comp)
60 .second;
61 }
62
63 template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
set_difference(_InputIterator1 __first1,_InputIterator1 __last1,_InputIterator2 __first2,_InputIterator2 __last2,_OutputIterator __result)64 inline _LIBCPP_HIDE_FROM_ABI _OutputIterator set_difference(
65 _InputIterator1 __first1,
66 _InputIterator1 __last1,
67 _InputIterator2 __first2,
68 _InputIterator2 __last2,
69 _OutputIterator __result) {
70 return std::__set_difference<_ClassicAlgPolicy>(__first1, __last1, __first2, __last2, __result, __less<>()).second;
71 }
72
73 _LIBCPP_END_NAMESPACE_STD
74
75 _LIBCPP_POP_MACROS
76
77 #endif // _LIBCPP___CXX03___ALGORITHM_SET_DIFFERENCE_H
78