BufferIterator are Random Access iterators

This commit is contained in:
Maxime Coste 2013-05-30 14:05:05 +02:00
parent d2df6a9f15
commit 07c8379313
2 changed files with 7 additions and 1 deletions

View File

@ -31,7 +31,7 @@ public:
typedef size_t difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef std::bidirectional_iterator_tag iterator_category;
typedef std::random_access_iterator_tag iterator_category;
BufferIterator() : m_buffer(nullptr) {}
BufferIterator(const Buffer& buffer, BufferCoord coord);
@ -44,6 +44,7 @@ public:
bool operator>= (const BufferIterator& iterator) const;
char operator* () const;
char operator[](size_t n) const;
size_t operator- (const BufferIterator& iterator) const;
BufferIterator operator+ (ByteCount size) const;

View File

@ -62,6 +62,11 @@ inline char BufferIterator::operator*() const
return m_buffer->at(m_coord);
}
inline char BufferIterator::operator[](size_t n) const
{
return m_buffer->at(m_buffer->advance(m_coord, n));
}
inline size_t BufferIterator::operator-(const BufferIterator& iterator) const
{
kak_assert(m_buffer == iterator.m_buffer);