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_UNION_H
10 #define _LIBCPP___ALGORITHM_RANGES_SET_UNION_H
11 
12 #include <__algorithm/in_in_out_result.h>
13 #include <__algorithm/make_projected.h>
14 #include <__algorithm/set_union.h>
15 #include <__config>
16 #include <__functional/identity.h>
17 #include <__functional/invoke.h>
18 #include <__functional/ranges_operations.h>
19 #include <__iterator/concepts.h>
20 #include <__iterator/iterator_traits.h>
21 #include <__iterator/mergeable.h>
22 #include <__iterator/projected.h>
23 #include <__ranges/access.h>
24 #include <__ranges/concepts.h>
25 #include <__ranges/dangling.h>
26 #include <__utility/forward.h>
27 #include <__utility/move.h>
28 
29 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
30 #  pragma GCC system_header
31 #endif
32 
33 #if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
34 
35 _LIBCPP_BEGIN_NAMESPACE_STD
36 
37 namespace ranges {
38 
39 template <class _InIter1, class _InIter2, class _OutIter>
40 using set_union_result = in_in_out_result<_InIter1, _InIter2, _OutIter>;
41 
42 namespace __set_union {
43 
44 struct __fn {
45   template <
46       input_iterator _InIter1,
47       sentinel_for<_InIter1> _Sent1,
48       input_iterator _InIter2,
49       sentinel_for<_InIter2> _Sent2,
50       weakly_incrementable _OutIter,
51       class _Comp  = ranges::less,
52       class _Proj1 = identity,
53       class _Proj2 = identity>
54     requires mergeable<_InIter1, _InIter2, _OutIter, _Comp, _Proj1, _Proj2>
55   _LIBCPP_HIDE_FROM_ABI constexpr set_union_result<_InIter1, _InIter2, _OutIter> operator()(
56       _InIter1 __first1,
57       _Sent1 __last1,
58       _InIter2 __first2,
59       _Sent2 __last2,
60       _OutIter __result,
61       _Comp __comp   = {},
62       _Proj1 __proj1 = {},
63       _Proj2 __proj2 = {}) const {
64     auto __ret = std::__set_union(
65         std::move(__first1),
66         std::move(__last1),
67         std::move(__first2),
68         std::move(__last2),
69         std::move(__result),
70         ranges::__make_projected_comp(__comp, __proj1, __proj2));
71     return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)};
72   }
73 
74   template <
75       input_range _Range1,
76       input_range _Range2,
77       weakly_incrementable _OutIter,
78       class _Comp  = ranges::less,
79       class _Proj1 = identity,
80       class _Proj2 = identity>
81     requires mergeable<
82         iterator_t<_Range1>,
83         iterator_t<_Range2>,
84         _OutIter,
85         _Comp,
86         _Proj1,
87         _Proj2>
88   _LIBCPP_HIDE_FROM_ABI constexpr set_union_result<borrowed_iterator_t<_Range1>,
89                                                    borrowed_iterator_t<_Range2>,
90                                                    _OutIter>
91     operator()(
92         _Range1&& __range1,
93         _Range2&& __range2,
94         _OutIter __result,
95         _Comp __comp   = {},
96         _Proj1 __proj1 = {},
97         _Proj2 __proj2 = {}) const {
98     auto __ret = std::__set_union(
99         ranges::begin(__range1),
100         ranges::end(__range1),
101         ranges::begin(__range2),
102         ranges::end(__range2),
103         std::move(__result),
104         ranges::__make_projected_comp(__comp, __proj1, __proj2));
105     return {std::move(__ret.__in1_), std::move(__ret.__in2_), std::move(__ret.__out_)};
106   }
107 };
108 
109 } // namespace __set_union
110 
111 inline namespace __cpo {
112   inline constexpr auto set_union = __set_union::__fn{};
113 } // namespace __cpo
114 } // namespace ranges
115 
116 _LIBCPP_END_NAMESPACE_STD
117 
118 #endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
119 
120 #endif // _LIBCPP___ALGORITHM_RANGES_SET_UNION_H
121