-
Notifications
You must be signed in to change notification settings - Fork 4
/
stdset_wrapper.h
93 lines (78 loc) · 1.33 KB
/
stdset_wrapper.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include <set>
template<class T>
class SetWrapper
{
private:
const std::set<T>& _set;
typename std::set<T>::const_iterator _iter;
public:
SetWrapper(const std::set<T>& original)
: _set( original )
{
_iter = _set.begin();
}
~SetWrapper()
{
}
int __len__()
{
return _set.size();
}
bool __contains__(T item)
{
std::set<T>::const_iterator iter = this->_set.find(item);
return iter != this->_set.end();
}
SetWrapper<T>* __iter__()
{
_iter = _set.begin();
return new SetWrapper<T>(_set);
}
T next()
{
if (_iter == _set.end())
{
return NULL;
}
return *(_iter++);
}
};
template<class T>
class SetWrapper_PtrNext
{
private:
const std::set<T>& _set;
typename std::set<T>::const_iterator _iter;
public:
SetWrapper_PtrNext(const std::set<T>& original)
: _set( original )
{
_iter = _set.begin();
}
~SetWrapper_PtrNext()
{
}
int __len__()
{
return _set.size();
}
bool __contains__(T item)
{
std::set<T>::const_iterator iter = this->_set.find(item);
return iter != this->_set.end();
}
SetWrapper_PtrNext<T>* __iter__()
{
_iter = _set.begin();
return new SetWrapper_PtrNext<T>(_set);
}
const T* next()
{
if (_iter == _set.end())
{
return NULL;
}
return &*(_iter++);
}
};