EDIT: This question was closed even though none of them talked about reverse iterators, so my question still stands
If you want to implement iterators correctly inside a custom container, in such way that supports STL algorithms and range-based for
loops you, must use an API and define some functions
and typedef
s.
What are the requirements of this API for iterators? and reverse iterators?
I know that for iterator (not reverse_iterator) you need your custom container to have the following and I don't know if there's anything else or this really is what you need: (the <>
represent a placeholder, and not a template for exmaple)
Inside the Container Class
typedef <IteratorClass> iterator;
typedef <ConstIteratorClass> const_iterator;
iterator begin ();
const_iterator begin () const;
const_iterator cbegin () const;
iterator end ();
const_iterator end () const;
const_iterator cend () const;
Inside the Iterator Class (and you need a const
iterator class as well)
typedef <ValueType> value_type;
typedef <ReferenceType> reference;
typedef <PointerType> pointer;
typedef <DiffType> difference_type;
typedef <IteratorCategory> iterator_category;
Does reverse Iterator require something similar?