-
Notifications
You must be signed in to change notification settings - Fork 0
/
filterfalse.hpp
61 lines (51 loc) · 1.56 KB
/
filterfalse.hpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#include <iostream>
using namespace std;
namespace itertools{
template <typename container, typename lambda>
class filterfalse{
container cont;
lambda condition;
public:
filterfalse(lambda co, container c): cont(c), condition(co){}
class iterator{
typename container::iterator it_begin;
typename container::iterator it_end;
lambda condition;
public:
iterator(typename container::iterator begin,typename container::iterator end,lambda co)
: it_begin(begin), it_end(end), condition(co){}
bool operator==(const iterator &it) const
{
return it_begin == it.it_begin;
}
bool operator!=(const iterator &it) const
{
return it_begin != it.it_begin;
}
iterator &operator++(){
++it_begin;
while (it_begin != it_end && condition(*it_begin))
{
it_begin++;
}
return *this;
}
const iterator operator++(int){
iterator temp = *this;
++(*this);
return temp;
}
decltype(*(cont.begin())) operator*(){
if(condition(*it_begin)) ++(*this);
return *it_begin;
}
};
iterator begin(){
return iterator(cont.begin(),cont.end(),this->condition);
}
iterator end(){
return iterator(cont.end(),cont.end(),this->condition);
}
};
}