-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.h
92 lines (73 loc) · 1.14 KB
/
util.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
#ifndef UTIL_H
#define UTIL_H
#include <vector>
#include <limits>
template<class T>
class CachedValue
{
protected:
bool _ready;
T _value;
public:
CachedValue()
: _ready(false)
{}
void reset()
{
_ready = false;
}
bool ready() const
{
return _ready;
}
void set_ready()
{
_ready = true;
}
const T & operator=(const T & value)
{
set_ready();
_value = value;
return _value;
}
const T & operator()(const T & value)
{
set_ready();
_value = value;
return _value;
}
operator const T&() const
{
return _value;
}
T& get()
{
return _value;
}
};
template<class ITER>
struct pair_iter : public std::pair<ITER, ITER>
{
typedef typename ITER::value_type single_v_type;
typedef std::pair<single_v_type *, single_v_type *> reference;
pair_iter(const ITER & i1, const ITER & i2)
: std::pair<ITER, ITER>(i1, i2)
{}
pair_iter & operator++()
{
this->first++;
this->second++;
return *this;
}
pair_iter operator++(int)
{
pair_iter ret(*this);
++*this;
return ret;
}
reference operator*()
{
return reference(&(*this->first), &(*this->second));
}
};
#endif //UTIL_H