-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathunique_justseen.hpp
More file actions
31 lines (27 loc) · 891 Bytes
/
unique_justseen.hpp
File metadata and controls
31 lines (27 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef ITER_UNIQUE_JUSTSEEN_HPP
#define ITER_UNIQUE_JUSTSEEN_HPP
#include "groupby.hpp"
#include "imap.hpp"
#include <iterator>
#include <utility>
namespace iter {
namespace impl {
struct UniqueJustseenFn
: PipeableAndBindOptionalSecond<UniqueJustseenFn, Identity> {
public:
using PipeableAndBindOptionalSecond<UniqueJustseenFn, Identity>::
operator();
template <typename Container, typename KeyFunc>
auto operator()(Container&& container, KeyFunc key_fn) const {
// decltype(auto) return type in lambda so reference types are preserved
return imap(
[](auto&& group) -> decltype(auto) {
return *get_begin(group.second);
},
groupby(std::forward<Container>(container), std::move(key_fn)));
}
};
}
inline constexpr impl::UniqueJustseenFn unique_justseen{};
}
#endif