-
Notifications
You must be signed in to change notification settings - Fork 0
array iterator
struct iterator
Points to a location in an array container.
-
typedef value_type type
so that generic wrappers can access the parent container'svalue_type
-
array<value_type> *root
is a pointer to the parent container. -
int index
is the location of this iterator designated by value.
iterator()
The default constructor. root
is set to NULL
and index
to 0
.
iterator(array<value_type> *root, int index)
This sets root
and index
directly. It's protected member that should only be used by the parent container.
operator bool()
checks whether this iterator points to a valid value in the array container.
value_type &operator*()
returns this iterator's value.
value_type *operator->()
The dot operator for this iterator's value.
value_type *ptr()
returns a pointer to this iterator's value.
value_type &get()
returns this iterator's value.
iterator &ref()
This is a placeholder function. It just returns the same iterator.
int idx()
returns the current index of this iterator. value - start
iterator &operator++()
Increments the iterator to the next index
.
iterator &operator--()
Decrements the iterator to the previous index
.
iterator &operator+=(int n)
Increments the iterator by n
.
iterator &operator-=(int n)
Decrements the iterator by n
.
iterator operator+(int n)
Returns the iterator n
elements ahead of this one.
iterator operator-(int n)
Returns the iterator n
elements behind this one.
bool operator==(iterator i)
bool operator!=(iterator i)
bool operator<(iterator i)
bool operator>(iterator i)
bool operator<=(iterator i)
bool operator>=(iterator i)
bool operator==(const_iterator i)
bool operator!=(const_iterator i)
bool operator<(const_iterator i)
bool operator>(const_iterator i)
bool operator<=(const_iterator i)
bool operator>=(const_iterator i)
Comparison operations between iterators compares index
.
int operator-(iterator i)
int operator-(const_iterator i)
Returns the number of elements between i
and this iterator.
slice<range<iterator> > sub(int length)
array<value_type> subcpy(int length)
Returns a slice or copy starting at this iterator for a given length
.
slice<range<iterator> > sub()
array<value_type> subcpy()
Returns a slice or copy from this iterator to the end of the container.
void alloc(int n = 1)
allocate n
new spaces at this index. The new spaces appear before the current value at this index.
void drop(int n = 1)
Deletes all elements in the range [this, this+n).
array<value_type> pop(int n = 1)
Pull all elements in the range [this, this+n) out of this array and into their own.
void push(value_type v)
Places the value v
into the array before the element pointed at by this iterator so that v
is located at this iterator.
void append(const container &c)
Places all of the elements in c
into the array before the element pointed at by this iterator so that the first one is located at this iterator.
void replace(int n, value_type v)
void replace(int n, const container &c)
replace the elements in the range [this, this+n) with the value v
or the elements in c
.
void swap(iterator_type i)
swap the values between these two iterators. The iterators are left unchanged.
iterator &operator=(iterator i)
set the index of this iterator equal to the index of another.
#include <std/ascii_stream.h>
#include <std/array.h>
using namespace core;
int main()
{
array<int> arr = array<int>::values(8, 9, 2, 4, 6, 4, 2, 8, 7);
for (array<int>::iterator i = arr.begin(); i != arr.end(); i++)
cout << i.idx() << ": " << *i << endl;
arr.at(3).drop(3);
cout << arr << endl;
return 0;
}
0: 9
1: 2
2: 4
3: 6
4: 4
5: 2
6: 8
7: 7
{9, 2, 4, 8, 7}