forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunique_justseen.hpp
More file actions
31 lines (25 loc) · 779 Bytes
/
Copy pathunique_justseen.hpp
File metadata and controls
31 lines (25 loc) · 779 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 <utility>
#include <iterator>
#include <initializer_list>
namespace iter {
template <typename Container>
auto unique_justseen(Container&& container) {
// explicit return type in lambda so reference types are preserved
return imap([](auto&& group) -> impl::iterator_deref<Container> {
return *std::begin(group.second);
}, groupby(std::forward<Container>(container)));
}
template <typename T>
auto unique_justseen(std::initializer_list<T> il) {
return imap(
[](auto&& group) -> impl::iterator_deref<std::initializer_list<T>> {
return *std::begin(group.second);
},
groupby(il));
}
}
#endif