File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#ifndef UNIQUE_JUSTSEEN_HPP
22#define UNIQUE_JUSTSEEN_HPP
33
4- #include " filter.hpp"
4+ #include " groupby.hpp"
5+ #include " imap.hpp"
56
67#include < type_traits>
78#include < functional>
89#include < utility>
910
1011namespace iter
1112{
12- // this should be self evident but unique_justseen places the requirement
13- // on the elements in the container have the != operator overloaded
13+ // gets first of each group. since each group is decided based on equality
14+ // with the previous item, this results in each item only appearing once
1415 template <typename Container>
15- auto unique_justseen (Container && container)
16- -> Filter<std::function<bool(decltype (container.front()))>,Container>
17- {
18- using elem_t = decltype (container.front ());
19- auto last = container.begin ();
20- std::function<bool (elem_t )> func = [last,container] (elem_t e) mutable
21- {
22- if (last == container.begin ()) {
23- return true ;
24- }
25- else {
26- return *(++last) != e;
27- }
28- };
29- return filter (func,std::forward<Container>(container));
16+ auto unique_justseen (Container&& container) {
17+ return imap (
18+ [] (iterator_deref<
19+ decltype (
20+ groupby (
21+ std::forward<Container>(container)))>&& gb)
22+ {return *std::begin (gb.second );},
23+ groupby (std::forward<Container>(container)));
3024 }
3125}
3226
You can’t perform that action at this time.
0 commit comments