Core utilities
Core utility library by Ross Smith
#include "rs-core/iterator.hpp"
namespace RS;
In this document:
I
is the iterator class being definedV
is the iterator’s value typeCV
is either V
or const V
depending on whether we want a mutable or constant iteratori, j
are objects of the iterator typev
is an object of the value typen
is an integertemplate <typename I> class OutputIterator;
template <typename I, typename CV> class InputIterator;
template <typename I, typename CV> class ForwardIterator;
template <typename I, typename CV> class BidirectionalIterator;
template <typename I, typename CV> class RandomAccessIterator;
template <typename I, typename CV> class ContiguousIterator;
These are a set of mixin classes that can be used to easily create iterators using the CRTP pattern.
Example:
class MyIterator:
public RS::ForwardIterator<MyIterator, const int> {
public:
const int& operator*() const;
MyIterator& operator++();
bool operator==(const MyIterator& i) const;
};
The table below shows which operations must be defined for each category of iterator, and which are automatically generated by the mixin base class.
Mixin class | Requires | Defines |
---|---|---|
OutputIterator |
i=v |
*i ++i i++ |
InputIterator ForwardIterator |
*i ++i i==j |
i-> i++ i!=j i<=>j |
BidirectionalIterator |
*i ++i --i i==j |
i-> i++ i-- i!=j i<=>j |
RandomAccessIterator ContiguousIterator |
*i i+=n i-j |
i-> i[n] ++i i++ --i i-- i-=n i+n n+i i-n i==j i!=j i<j i>j i<=j i>=j i<=>j |