Iros
 
Loading...
Searching...
No Matches
set_union.h
Go to the documentation of this file.
1#pragma once
2
8
9namespace di::container {
10namespace detail {
12 template<concepts::InputIterator It1, concepts::SentinelFor<It1> Sent1, concepts::InputIterator It2,
13 concepts::SentinelFor<It2> Sent2, concepts::WeaklyIncrementable Out, typename Comp = function::Compare,
14 typename Proj1 = function::Identity, typename Proj2 = function::Identity>
16 constexpr auto operator()(It1 first1, Sent1 last1, It2 first2, Sent2 last2, Out out, Comp comp = {},
17 Proj1 proj1 = {}, Proj2 proj2 = {}) const -> InInOutResult<It1, It2, Out> {
18 // While both ranges are non-empty, compare them to see which elements should be copied to output.
19 for (; first1 != last1 && first2 != last2; ++out) {
20 auto result =
21 function::invoke(comp, function::invoke(proj1, *first1), function::invoke(proj2, *first2));
22 if (result < 0) {
23 // Element was smaller, take from range 1.
24 *out = *first1++;
25 } else if (result > 0) {
26 // Element was larger, take from range 2.
27 *out = *first2++;
28 } else {
29 // Element is equal, skip value from range 2.
30 *out = ++first1;
31 ++first2;
32 }
33 }
34
35 // Copy and remaining parts of the input to output.
36 auto [end1, out_next] = container::copy(util::move(first1), last1, util::move(out));
37 auto [end2, out_final] = container::copy(util::move(first2), last2, util::move(out_next));
38 return { util::move(end1), util::move(end2), util::move(out_final) };
39 }
40
41 template<concepts::InputContainer Con1, concepts::InputContainer Con2, concepts::WeaklyIncrementable Out,
42 typename Comp = function::Compare, typename Proj1 = function::Identity,
43 typename Proj2 = function::Identity>
44 requires(
45 concepts::Mergeable<meta::ContainerIterator<Con1>, meta::ContainerIterator<Con2>, Out, Comp, Proj1, Proj2>)
46 constexpr auto operator()(Con1&& container1, Con2&& container2, Out out, Comp comp = {}, Proj1 proj1 = {},
47 Proj2 proj2 = {}) const
49 return (*this)(container::begin(container1), container::end(container1), container::begin(container2),
50 container::end(container2), util::move(out), util::ref(comp), util::ref(proj1),
51 util::ref(proj2));
52 }
53 };
54}
55
56constexpr inline auto set_union = detail::SetUnionFunction {};
57}
58
59namespace di {
61}
Definition mergeable.h:14
Definition sequence.h:13
Definition sequence.h:12
constexpr auto set_union
Definition set_union.h:56
constexpr auto end
Definition end.h:47
constexpr auto copy
Definition copy.h:30
constexpr auto begin
Definition begin.h:44
constexpr auto invoke
Definition invoke.h:100
Conditional< concepts::BorrowedContainer< Con >, ContainerIterator< Con >, container::Dangling > BorrowedIterator
Definition borrowed_iterator.h:11
decltype(container::begin(util::declval< T & >())) ContainerIterator
Definition container_iterator.h:8
constexpr auto ref
Definition reference_wrapper.h:98
Definition zstring_parser.h:9