Core utilities
Core utility library by Ross Smith
#include "rs-core/iterator.hpp"
namespace RS;
template <typename I, typename CV, typename Guide> class Iterator;
This is a mixin class that can be used to easily create iterators using the CRTP pattern. In the template parameters:
I is the iterator class being defined.CV is either the iterator’s value_type or const value_type depending on whether we want a mutable or constant iterator.Guide is a type used to indicate the intended iterator category. It can be one of:
The table below shows which operations must be defined for each category of iterator, and which are automatically generated by the mixin base class.
In this table:
i, j are objects of the iterator type.v is an object of the value type.n is an integer.| Iterator category | Requires | Defines |
|---|---|---|
| Output | i=v |
*i ++i i++ |
| Input Forward |
*i ++i i==j |
i-> i++ i!=j i<=>j |
| Bidirectional | *i ++i --i i==j |
i-> i++ i-- i!=j i<=>j |
| Random access Contiguous |
*i i+=n i-j |
i-> i[n] ++i i++ --i i-- i-=n i+n n+ii-n i==j i!=j i<j i>j i<=j i>=j i<=>j |
Example:
class MyIterator:
public RS::Iterator<MyIterator, const int, std::forward_iterator_category> {
public:
const int& operator*() const;
MyIterator& operator++();
bool operator==(const MyIterator& i) const;
};