commit 48dacef02c806af924290e660a37b3800068010f parent 12822ce7fc92ef98c7b29f55be35eae132b28e3e Author: Michael Savage <mikejsavage@gmail.com> Date: Fri Dec 9 23:31:24 +0200 Add Array::begin/end Diffstat:
array.h | | | 30 | ++++++++++++++++++++++++++++++ |
diff --git a/array.h b/array.h @@ -6,6 +6,28 @@ #include "intrinsics.h" template< typename T > +class ArrayIterator { +public: + ArrayIterator( T * ptr ) { + cursor = ptr; + } + + T & operator*() { + return *cursor; + } + + bool operator!=( ArrayIterator< T > other ) { + return cursor != other.cursor; + } + + void operator++() { + cursor++; + } +private: + T * cursor; +}; + +template< typename T > class array { public: array() { @@ -54,6 +76,14 @@ public: return sizeof( T ) * n; } + ArrayIterator< T > begin() { + return ArrayIterator< T >( elems ); + } + + ArrayIterator< T > end() { + return ArrayIterator< T >( elems + n ); + } + size_t n; protected: