-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.c++
51 lines (42 loc) · 1.01 KB
/
next.c++
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
#include <iterator>
template<class T>
class NextIterator{
public:
class iterator{
using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = T;
using pointer = T*;
using reference = T&;
NextIterator *source;
T *content;
public:
explicit iterator(NextIterator<T> *source):source(source),content(source->getLine()){}
explicit iterator(NextIterator<T> *source,std::string *content):source(source),content(content){}
iterator& operator++(){
content=source->getLine();
return *this;
}
iterator operator++(int){
iterator retval = *this;
++(*this);
return retval;
}
bool operator==(iterator other) const {
return content == other.content;
}
bool operator!=(iterator other) const {
return !(*this == other);
}
reference operator*() const {
return *content;
}
};
iterator begin(){
return iterator(this);
}
iterator end(){
return iterator(this,NULL);
}
virtual T *next()=0;
};