-
Notifications
You must be signed in to change notification settings - Fork 0
/
compress.hpp
62 lines (53 loc) · 1.54 KB
/
compress.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
62
#pragma once
#include <iostream>
using namespace std;
namespace itertools{
template <typename container1, typename container2>
class compress{
container1 cont1;
container2 cont2;
public:
compress(container1 co1, container2 co2): cont1(co1), cont2(co2){}
class iterator{
typename container1::iterator a;
typename container2::iterator b;
typename container1::iterator it_end;
public:
iterator(typename container1::iterator _a,typename container2::iterator _b, typename container1::iterator end)
: a(_a), b(_b), it_end(end){}
bool operator==(const iterator &it) const
{
return a == it.a;
}
bool operator!=(const iterator &it) const
{
return a != it.a;
}
iterator &operator++(){
a++;
b++;
while (a != it_end && !(*b))
{
a++;
b++;
}
return *this;
}
const iterator operator++(int){
iterator temp = *this;
++(*this);
return temp;
}
decltype(*(cont1.begin())) operator*(){
if(!(*b)) ++(*this);
return *a;
}
};
iterator begin(){
return iterator(cont1.begin(),cont2.begin(),cont1.end());
}
iterator end(){
return iterator(cont1.end(),cont2.begin(),cont1.end());
}
};
}