| 1 |
class iterator: public Iterator |
| 2 |
{ |
| 3 |
friend class StringPtr; |
| 4 |
|
| 5 |
std::vector<std::string *>::iterator d_current; |
| 6 |
|
| 7 |
iterator(std::vector<std::string *>::iterator const ¤t) |
| 8 |
: |
| 9 |
d_current(current) |
| 10 |
{} |
| 11 |
|
| 12 |
public: |
| 13 |
iterator &operator--() |
| 14 |
{ |
| 15 |
--d_current; |
| 16 |
return *this; |
| 17 |
} |
| 18 |
iterator operator--(int) |
| 19 |
{ |
| 20 |
return iterator(d_current--); |
| 21 |
} |
| 22 |
iterator &operator++() |
| 23 |
{ |
| 24 |
++d_current; |
| 25 |
return *this; |
| 26 |
} |
| 27 |
bool operator==(iterator const &other) const |
| 28 |
{ |
| 29 |
return d_current == other.d_current; |
| 30 |
} |
| 31 |
bool operator!=(iterator const &other) const |
| 32 |
{ |
| 33 |
return d_current != other.d_current; |
| 34 |
} |
| 35 |
int operator-(iterator const &rhs) const |
| 36 |
{ |
| 37 |
return d_current - rhs.d_current; |
| 38 |
} |
| 39 |
std::string &operator*() const |
| 40 |
{ |
| 41 |
return **d_current; |
| 42 |
} |
| 43 |
bool operator<(iterator const &other) const |
| 44 |
{ |
| 45 |
return **d_current < **other.d_current; |
| 46 |
} |
| 47 |
iterator operator+(int step) const |
| 48 |
{ |
| 49 |
return iterator(d_current + step); |
| 50 |
} |
| 51 |
iterator operator-(int step) const |
| 52 |
{ |
| 53 |
return iterator(d_current - step); |
| 54 |
} |
| 55 |
|
| 56 |
// the following members are not used by sort(), but they |
| 57 |
// might come in handy in other situations: |
| 58 |
iterator &operator+=(int step) // increment the iterator |
| 59 |
{ // over `n' steps |
| 60 |
d_current += step; |
| 61 |
return *this; |
| 62 |
} |
| 63 |
iterator &operator-=(int step) // decrement the iterator |
| 64 |
{ // over `n' steps |
| 65 |
d_current -= step; |
| 66 |
return *this; |
| 67 |
} |
| 68 |
std::string *operator->() const // access the fields of the |
| 69 |
{ // struct an iterator points |
| 70 |
return *d_current; // to. E.g., it->length() |
| 71 |
} |
| 72 |
}; |