rs-core

Core utilities


Project maintained by CaptainCrowbar Hosted on GitHub Pages — Theme by mattgraham

Iterator Base Classes

Core utility library by Ross Smith

#include "rs-core/iterator.hpp"
namespace RS;

Contents

Iterator base classes

In this document:

template <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