Skip to content

Array Iterator

Spice
import "std/iterator/array-iterator";

ArrayIterator<I> struct

Implements: IIterator<I>

An ArrayIterator in Spice can be used to iterate over an arbitrary array

Constructors

ctor

Spice
public p ArrayIterator.ctor(I[] array, unsigned long size)

Construct an array iterator over the given array

Parameters

Name Type Description
array I[] Array to iterate over
size unsigned long Number of items in the array

Methods

get

Spice
public inline f<I&> ArrayIterator.get()

Returns the current item of the array

Returns: I& — Reference to the current item

getIdx

Spice
public inline f<Pair<unsigned long, I&>> ArrayIterator.getIdx()

Returns the current index and the current item of the array

Returns: Pair<unsigned long, I&> — Pair of current index and reference to the current item

isValid

Spice
public inline const f<bool> ArrayIterator.isValid()

Check if the iterator is valid

Returns: bool — true or false

next

Spice
public inline p ArrayIterator.next()

Returns the current item of the array and moves the cursor to the next one

Functions

iterate

Spice
public inline f<ArrayIterator<I>> iterate<I>(I[] array, unsigned long size)

Convenience wrapper for creating a simple array iterator

Parameters

Name Type Description
array I[]
size unsigned long

Returns: ArrayIterator<I>

Operators

operator++

Spice
public inline p operator++<I>(ArrayIterator<I>& it)

Advances the cursor by one

Parameters

Name Type Description
it ArrayIterator<I>& ArrayIterator

operator--

Spice
public inline p operator--<I>(ArrayIterator<I>& it)

Move the cursor back by one

Parameters

Name Type Description
it ArrayIterator<I>& ArrayIterator

operator+=

Spice
public inline p operator+=<I, Numeric>(ArrayIterator<I>& it, Numeric offset)

Advances the cursor by the given offset

Parameters

Name Type Description
it ArrayIterator<I>& ArrayIterator
offset Numeric Offset

operator-=

Spice
public inline p operator-=<I, Numeric>(ArrayIterator<I>& it, Numeric offset)

Move the cursor back by the given offset

Parameters

Name Type Description
it ArrayIterator<I>& ArrayIterator
offset Numeric Offset