1 #ifndef PandaTree_Framework_Iterator_h 2 #define PandaTree_Framework_Iterator_h 10 template<
class C,
bool is_const>
12 typedef C container_type;
16 friend container_type;
20 typedef int difference_type;
22 typedef typename C::value_type value_type;
23 typedef typename std::conditional<is_const, typename C::const_reference, typename C::reference>::type reference;
24 typedef typename std::conditional<is_const, typename C::const_pointer, typename C::pointer>::type pointer;
25 typedef std::random_access_iterator_tag iterator_category;
28 Iterator(mutable_type
const& it) : unitSize_(it.unitSize_) { ptr_.obj = it.ptr_.obj; }
31 self_type& operator=(const_type
const& rhs) { ptr_.obj = rhs.ptr_.obj;
return *
this; }
32 self_type& operator=(mutable_type
const& rhs) { ptr_.obj = rhs.ptr_.obj;
return *
this; }
34 bool operator==(mutable_type
const& rhs)
const {
return ptr_.obj == rhs.ptr_.obj; }
35 bool operator==(const_type
const& rhs)
const {
return ptr_.obj == rhs.ptr_.obj; }
36 bool operator!=(mutable_type
const& rhs)
const {
return ptr_.obj != rhs.ptr_.obj; }
37 bool operator!=(const_type
const& rhs)
const {
return ptr_.obj != rhs.ptr_.obj; }
39 self_type& operator++() { shiftPtr_(1);
return *
this; }
40 self_type operator++(
int) {
auto itr(*
this); shiftPtr_(1);
return itr; }
41 self_type& operator--() { shiftPtr_(-1);
return *
this; }
42 self_type operator--(
int) {
auto itr(*
this); shiftPtr_(-1);
return itr; }
44 self_type& operator+=(
int n) { shiftPtr_(n);
return *
this; }
45 self_type& operator-=(
int n) { shiftPtr_(-n);
return *
this; }
47 self_type operator+(
int n)
const {
auto itr(*
this);
return (itr += n); }
48 self_type operator-(
int n)
const {
auto itr(*
this);
return (itr -= n); }
50 reference operator*()
const {
return *ptr_.obj; }
51 pointer operator->()
const {
return ptr_.obj; }
53 int operator-(self_type
const& rhs)
const {
return ptr_.obj - rhs.operator->(); }
54 reference operator[](
int n)
const {
auto itr(*
this);
return *(itr += n); }
56 bool operator<(self_type
const& rhs)
const {
return this->operator-(rhs) < 0; }
57 bool operator>(self_type
const& rhs)
const {
return this->operator-(rhs) > 0; }
58 bool operator<=(self_type
const& rhs)
const {
return !(this->operator>(rhs)); }
59 bool operator>=(self_type
const& rhs)
const {
return !(this->operator<(rhs)); }
62 Iterator(pointer p,
unsigned unitSize) : unitSize_(unitSize) { ptr_.obj = p; }
64 void shiftPtr_(
int shift) { ptr_.ch += unitSize_ * shift; }
66 typedef typename std::conditional<is_const, char const*, char*>::type char_pointer;
72 unsigned const unitSize_{0};
Iterator class for containers.
Definition: Iterator.h:11