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_RANGES_SET_DIFFERENCE_H
10#define _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H
11
12#include <__algorithm/in_out_result.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/set_difference.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/ranges_operations.h>
18#include <__iterator/concepts.h>
19#include <__iterator/mergeable.h>
20#include <__ranges/access.h>
21#include <__ranges/concepts.h>
22#include <__ranges/dangling.h>
23#include <__utility/move.h>
24
25#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
26# pragma GCC system_header
27#endif
28
29_LIBCPP_PUSH_MACROS
30#include <__undef_macros>
31
32#if _LIBCPP_STD_VER >= 20
33
34_LIBCPP_BEGIN_NAMESPACE_STD
35
36namespace ranges {
37
38template <class _InIter, class _OutIter>
39using set_difference_result = in_out_result<_InIter, _OutIter>;
40
41struct __set_difference {
42 template <input_iterator _InIter1,
43 sentinel_for<_InIter1> _Sent1,
44 input_iterator _InIter2,
45 sentinel_for<_InIter2> _Sent2,
46 weakly_incrementable _OutIter,
47 class _Comp = less,
48 class _Proj1 = identity,
49 class _Proj2 = identity>
50 requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2>
51 _LIBCPP_HIDE_FROM_ABI constexpr set_difference_result<_InIter1, _OutIter> operator()(
52 _InIter1 __first1,
53 _Sent1 __last1,
54 _InIter2 __first2,
55 _Sent2 __last2,
56 _OutIter __result,
57 _Comp __comp = {},
58 _Proj1 __proj1 = {},
59 _Proj2 __proj2 = {}) const {
60 return std::__set_difference(
61 __first1, __last1, __first2, __last2, __result, ranges::__make_projected_comp(__comp, __proj1, __proj2));
62 }
63
64 template <input_range _Range1,
65 input_range _Range2,
66 weakly_incrementable _OutIter,
67 class _Comp = less,
68 class _Proj1 = identity,
69 class _Proj2 = identity>
70 requires mergeable<iterator_t<_Range1>, iterator_t<_Range2>, _OutIter, _Comp, _Proj1, _Proj2>
71 _LIBCPP_HIDE_FROM_ABI constexpr set_difference_result<borrowed_iterator_t<_Range1>, _OutIter>
72 operator()(_Range1&& __range1,
73 _Range2&& __range2,
74 _OutIter __result,
75 _Comp __comp = {},
76 _Proj1 __proj1 = {},
77 _Proj2 __proj2 = {}) const {
78 return std::__set_difference(
79 ranges::begin(__range1),
80 ranges::end(__range1),
81 ranges::begin(__range2),
82 ranges::end(__range2),
83 __result,
84 ranges::__make_projected_comp(__comp, __proj1, __proj2));
85 }
86};
87
88inline namespace __cpo {
89inline constexpr auto set_difference = __set_difference{};
90} // namespace __cpo
91} // namespace ranges
92
93_LIBCPP_END_NAMESPACE_STD
94
95#endif // _LIBCPP_STD_VER >= 20
96
97_LIBCPP_POP_MACROS
98
99#endif // _LIBCPP___ALGORITHM_RANGES_SET_DIFFERENCE_H
100