Skip to content

array const_iterator

Ned Bingham edited this page Mar 11, 2017 · 1 revision

std/array.h


array

  • struct const_iterator

Points to a location in an array container.

Member Types

  • typedef value_type type so that generic wrappers can access the parent container's value_type

Member Variables

  • const array<value_type> *root is a pointer to the parent container.
  • int index is the location of this iterator designated by value.

Member Functions

Constructor

iterator()

The default constructor. root is set to NULL and index to 0.

const_iterator(iterator copy)

A copy constructor to convert an iterator to a const_iterator.

iterator(const 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.

Utility

operator bool() checks whether this iterator points to a valid value in the array container.

Accessors

const value_type &operator*() returns this iterator's value.

const value_type *operator->() The dot operator for this iterator's value.

const value_type *ptr() returns a pointer to this iterator's value.

const value_type &get() returns this iterator's value.

const_iterator &ref() This is a placeholder function. It just returns the same iterator.

int idx() returns the current index of this iterator. value - start

Iteration

const_iterator &operator++() Increments the iterator to the next index.

const_iterator &operator--() Decrements the iterator to the previous index.

const_iterator &operator+=(int n) Increments the iterator by n.

const_iterator &operator-=(int n) Decrements the iterator by n.

const_iterator operator+(int n) Returns the iterator n elements ahead of this one.

const_iterator operator-(int n) Returns the iterator n elements behind this one.

Comparison

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.

Slicing

slice<range<const_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<const_iterator> > sub()
array<value_type> subcpy()

Returns a slice or copy from this iterator to the end of the container.

Modifiers

const_iterator &operator=(const_iterator i)
const_iterator &operator=(iterator i)

set the index of this iterator equal to the index of another.

Examples

#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>::const_iterator i = arr.begin(); i != arr.end(); i++)
        cout << i.idx() << ": " << *i << endl;
    return 0;
}
0: 9
1: 2
2: 4
3: 6
4: 4
5: 2
6: 8
7: 7

Simple Containers

Standard Containers

Interface Containers

Specialized Containers

Input/Output

Algorithm

Clone this wiki locally