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 class

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:

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:

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+i
i-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;
};