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