Files Classes Functions Hierarchy
00001 #ifndef ITERATORS_H 00002 #define ITERATORS_H 00003 00004 #include <typedefs.h> 00005 00006 /* 00007 Interface for iterators. 00008 00009 Formed from an algorithmic perpective 00010 as contrasted with STL's minimal functional perspective. 00011 00012 In essence there needs to be a start/initialization 00013 which I call reset(); 00014 00015 The forwarding operation ++. 00016 00017 The access () or *. 00018 00019 Is the iterator in a valid state with the ! 00020 operator used to symbolicly do this in 00021 a visually compact way e.g. !myiter 00022 00023 I have used this interface in my workspace, 00024 and found it to be intuitive and useful. 00025 00026 With the for loop it is also very consise. 00027 00028 for ( myiter.reset(); !myiter; ++myiter) 00029 { ... 00030 dosomething( myiter() ) ... 00031 } 00032 */ 00033 00038 template< typename Cont, typename Tp > 00039 class stl_iterator 00040 { 00041 Cont & container; 00042 typename Cont::iterator current; 00043 public: 00044 00046 stl_iterator(Cont & container_) 00047 : container(container_) { current=container.begin(); } 00048 00050 void reset() 00051 { current=container.begin(); } 00052 00054 boolc operator !() 00055 { return current != container.end(); } 00056 00058 void operator ++() 00059 { ++current; } 00061 Tp & operator * () 00062 { return *current; } 00064 Tp const & operator ()() const 00065 { return *current; } 00066 00067 }; 00068 00069 00070 00071 #endif 00072
1.5.8