Core utilities
Core utility library by Ross Smith
#include "rs-core/iterator.hpp"
namespace RS;
template <typename I, typename V> concept ReadableIterator;
template <typename I, typename V> concept ReadableForwardIterator;
template <typename I, typename V> concept ReadableBidirectionalIterator;
template <typename I, typename V> concept ReadableRandomAccessIterator;
template <typename I, typename V> concept ReadableContiguousIterator;
template <typename I, typename V> concept WritableIterator;
template <typename I, typename V> concept WritableForwardIterator;
template <typename I, typename V> concept WritableBidirectionalIterator;
template <typename I, typename V> concept WritableRandomAccessIterator;
template <typename I, typename V> concept WritableContiguousIterator;
template <typename I, typename V> concept ReadWriteIterator;
template <typename I, typename V> concept ReadWriteForwardIterator;
template <typename I, typename V> concept ReadWriteBidirectionalIterator;
template <typename I, typename V> concept ReadWriteRandomAccessIterator;
template <typename I, typename V> concept ReadWriteContiguousIterator;
Iterator concepts compatible with specific value types. All of these require
I to be an iterator of the appropriate type. ReadableIterator also
requires a dereferenced iterator to be assignable to a V object;
WritableIterator requires a dereferenced iterator to be assignable from a
V object.
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 any 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_tag> {
public:
const int& operator*() const;
MyIterator& operator++();
bool operator==(const MyIterator& i) const;
};