Iros
 
Loading...
Searching...
No Matches
set_symmetric_difference.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 some element is present in both ranges.
19 while (first1 != last1 && first2 != last2) {
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 ++out;
26 } else if (result > 0) {
27 // Element was larger, take from range 2.
28 *out = *first2++;
29 ++out;
30 } else {
31 // Element is equal, skip.
32 ++first1;
33 ++first2;
34 }
35 }
36
37 // Copy and remaining parts of the input to output.
38 auto [end1, out_next] = container::copy(util::move(first1), last1, util::move(out));
39 auto [end2, out_final] = container::copy(util::move(first2), last2, util::move(out_next));
40 return { util::move(end1), util::move(end2), util::move(out_final) };
41 }
42
43 template<concepts::InputContainer Con1, concepts::InputContainer Con2, concepts::WeaklyIncrementable Out,
44 typename Comp = function::Compare, typename Proj1 = function::Identity,
45 typename Proj2 = function::Identity>
46 requires(
47 concepts::Mergeable<meta::ContainerIterator<Con1>, meta::ContainerIterator<Con2>, Out, Comp, Proj1, Proj2>)
48 constexpr auto operator()(Con1&& container1, Con2&& container2, Out out, Comp comp = {}, Proj1 proj1 = {},
49 Proj2 proj2 = {}) const
51 return (*this)(container::begin(container1), container::end(container1), container::begin(container2),
52 container::end(container2), util::move(out), util::ref(comp), util::ref(proj1),
53 util::ref(proj2));
54 }
55 };
56}
57
59}
60
61namespace di {
63}
Definition mergeable.h:14
Definition sequence.h:13
Definition sequence.h:12
constexpr auto set_symmetric_difference
Definition set_symmetric_difference.h:58
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
Definition set_symmetric_difference.h:11