Iros
 
Loading...
Searching...
No Matches
set_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 -> InOutResult<It1, Out> {
18 // While both ranges are non-empty, see if the current element in range 1 is present in range 2.
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 equal, so skip.
24 ++first1;
25 ++first2;
26 } else if (result < 0) {
27 // Element is before the current start of range 2. Therefore, it
28 // could not have been in range 2.
29 *out = *first1++;
30 ++out;
31 } else {
32 // Element is after the current start of range 2. Advance range 2
33 // to see if the start of range 1 is present.
34 ++first2;
35 }
36 }
37
38 // Copy and remaining parts of range 1 to output.
39 return container::copy(util::move(first1), last1, util::move(out));
40 }
41
42 template<concepts::InputContainer Con1, concepts::InputContainer Con2, concepts::WeaklyIncrementable Out,
43 typename Comp = function::Compare, typename Proj1 = function::Identity,
44 typename Proj2 = function::Identity>
45 requires(
46 concepts::Mergeable<meta::ContainerIterator<Con1>, meta::ContainerIterator<Con2>, Out, Comp, Proj1, Proj2>)
47 constexpr auto operator()(Con1&& container1, Con2&& container2, Out out, Comp comp = {}, Proj1 proj1 = {},
48 Proj2 proj2 = {}) const -> InOutResult<meta::BorrowedIterator<Con1>, Out> {
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
57}
58
59namespace di {
61}
Definition mergeable.h:14
Definition sequence.h:13
Definition sequence.h:12
constexpr auto set_difference
Definition set_difference.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
Definition set_difference.h:11