Checked_iter
Hi,
I try configure Checked_iter but not complate.
Could you be helpful me ? Could you be helpful me ?
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 94 95 96 97 98 99 100
|
template<class Cont, class iter = typename Cont::iterator>
class Checked_iter : public iterator_traits<iter>{
iter curr;
Cont *c;
public:
void valid(iter p)
{
if (c->end() == p)
return;
for (iter pp = c->begin(); pp != c->end() ++pp)
if (pp == p)
return;
throw out_of_range;
}
friend bool operator ==(const Checked_iter &i, const Checked_iter &j)
{
return i.c == j.c && i.curr == j.curr;
}
Checked_iter(Cont &x, iter p):c(x), curr(p){valid(p);}
reference_type operator *()
{
if (curr == c->end())
throw out_of_range;
return *curr;
}
pointer_type operator->()
{
return &*curr;
}
Checked_iter operator+(Dist d)
{
if (c->end() - curr <= d)
throw out_of_range;
return Checked_iter(c, curr + d);
}
reference_type operator[](Dist d)
{
if (c->end() - curr <= d)
throw out_of_range;
return c[d];
}
Checked_iter &operator++()
{
if (cuur == c->end())
throw out_of_range;
++curr;
return *this;
}
Checked_iter &operator++(int)
{
Checked_iter tmp = *this;
++*this;
return tmp;
}
Checked_iter &operator--()
{
if (cuur == c->end())
throw out_of_range;
--curr;
return *this;
}
Checked_iter &operator--(int)
{
Checked_iter tmp = *this;
--*this;
return tmp;
}
difference_type index()
{
return curr - c.begin();
}
iter unchecked()
{
return curr;
}
friend bool operator ==(const Checked_iter &i, const Checked_iter &j);
};
bool operator ==(const Checked_iter &i, const Checked_iter &j)
{
return i.c == j.c && i.curr == j.curr;
}
|
thank in advance...
Last edited on
Topic archived. No new replies allowed.