May 2017
Intermediate to advanced
590 pages
17h 18m
English
For this recipe, you should know the types of iterators the standard defines and how they are different. A good overview of their requirements is available at http://www.cplusplus.com/reference/iterator/.
To exemplify how to write a random access iterator, we will consider a variant of the dummy_array class used in the Enabling range-based for loops for custom types recipe of Chapter 1, Learning Modern Core Language Features. This is a very simple array concept, with no practical value, other than serving as a code base for demonstrating iterators:
template <typename Type, size_t const SIZE> class dummy_array { Type data[SIZE] = {}; public: Type& operator[](size_t const index) { if (index < SIZE) return data[index]; throw std::out_of_range("index ...Read now
Unlock full access