forked from ryanhaining/cppitertools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunique_everseen.hpp
More file actions
33 lines (28 loc) · 861 Bytes
/
Copy pathunique_everseen.hpp
File metadata and controls
33 lines (28 loc) · 861 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
32
33
#ifndef ITER_UNIQUE_EVERSEEN_HPP_
#define ITER_UNIQUE_EVERSEEN_HPP_
#include "internal/iterbase.hpp"
#include "filter.hpp"
#include <type_traits>
#include <functional>
#include <utility>
#include <unordered_set>
#include <iterator>
namespace iter {
template <typename Container>
auto unique_everseen(Container&& container) {
using elem_type = impl::iterator_deref<Container>;
auto func = [elem_seen = std::unordered_set<std::decay_t<elem_type>>()](
const elem_type& e) mutable {
return elem_seen.insert(e).second;
};
return filter(func, std::forward<Container>(container));
}
template <typename T>
auto unique_everseen(std::initializer_list<T> il) {
auto func = [elem_seen = std::unordered_set<T>()](const T& e) mutable {
return elem_seen.insert(e).second;
};
return filter(func, il);
}
}
#endif