Iros
 
Loading...
Searching...
No Matches
unique.h
Go to the documentation of this file.
1#pragma once
2
7
8namespace di::container {
9namespace detail {
11 template<concepts::Permutable It, concepts::SentinelFor<It> Sent, typename Proj = function::Identity,
12 concepts::IndirectEquivalenceRelation<meta::Projected<It, Proj>> Comp = function::Equal>
13 constexpr auto operator()(It first, Sent last, Comp comp = {}, Proj proj = {}) const -> View<It> {
14 // Find the first element where duplicate elements occur.
15 auto fast = container::adjacent_find(util::move(first), last, util::ref(comp), util::ref(proj));
16 if (fast == last) {
17 return { fast, fast };
18 }
19
20 // Since we know there are duplicates, advance the iterator to an
21 // element which may or may not be a duplicate. Then, keep advancing the
22 // fast iterator while it is a duplicate. Once it is not, output a new
23 // value.
24 auto slow = fast++;
25 while (++fast != last) {
26 if (!function::invoke(comp, function::invoke(proj, *slow), function::invoke(proj, *fast))) {
27 ++slow;
28 *slow = container::iterator_move(fast);
29 }
30 }
31 return { container::next(slow), util::move(fast) };
32 }
33
34 template<concepts::ForwardContainer Con, typename Proj = function::Identity,
35 concepts::IndirectEquivalenceRelation<meta::Projected<meta::ContainerIterator<Con>, Proj>> Comp =
36 function::Equal>
37 requires(concepts::Permutable<meta::ContainerIterator<Con>>)
38 constexpr auto operator()(Con&& container, Comp comp = {}, Proj proj = {}) const -> meta::BorrowedView<Con> {
40 }
41 };
42}
43
44constexpr inline auto unique = detail::UniqueFunction {};
45}
46
47namespace di {
49}
Definition view.h:35
Definition sequence.h:13
Definition sequence.h:12
constexpr auto next
Definition next.h:35
constexpr auto unique
Definition unique.h:44
constexpr auto adjacent_find
Definition adjacent_find.h:37
constexpr auto iterator_move
Definition iterator_move.h:56
constexpr auto end
Definition end.h:47
constexpr auto begin
Definition begin.h:44
constexpr auto invoke
Definition invoke.h:100
Conditional< concepts::BorrowedContainer< Con >, container::View< ContainerIterator< Con > >, container::Dangling > BorrowedView
Definition borrowed_view.h:12
constexpr auto ref
Definition reference_wrapper.h:98
Definition zstring_parser.h:9
constexpr auto proj
Definition proj.h:59
constexpr auto operator()(It first, Sent last, Comp comp={}, Proj proj={}) const -> View< It >
Definition unique.h:13