Skip to content

Number Iterator

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

NumberIterator<N> struct

Implements: IIterator<N>

A NumberIterator in Spice can be used to iterate over a range of numbers

Constructors

ctor

Spice
public p NumberIterator.ctor(N lowerBound, N upperBound)

Construct a number iterator over the inclusive range [lowerBound, upperBound]

Parameters

Name Type Description
lowerBound N Inclusive lower bound of the range
upperBound N Inclusive upper bound of the range

Methods

get

Spice
public inline f<N&> NumberIterator.get()

Returns the current number of the number range

Returns: N& — Reference to the current number

getIdx

Spice
public inline f<Pair<unsigned long, N&>> NumberIterator.getIdx()

Returns the current index and the current number of the number range

Returns: Pair<unsigned long, N&> — Pair of current index and a reference to the current number

isValid

Spice
public inline f<bool> NumberIterator.isValid()

Check if the iterator is valid

Returns: bool — true or false

next

Spice
public inline p NumberIterator.next()

Returns the current number of the number range and moves the cursor to the next item

Functions

range

Spice
public inline f<NumberIterator<N>> range<N>(N begin, N end)

Convenience wrapper for creating a simple number iterator

Parameters

Name Type Description
begin N
end N

Returns: NumberIterator<N>

Operators

operator++

Spice
public inline p operator++<N>(NumberIterator<N>& it)

Advances the cursor by one

Parameters

Name Type Description
it NumberIterator<N>& NumberIterator

operator--

Spice
public inline p operator--<N>(NumberIterator<N>& it)

Move the cursor back by one

Parameters

Name Type Description
it NumberIterator<N>& NumberIterator

operator+=

Spice
public inline p operator+=<N>(NumberIterator<N>& it, N offset)

Advances the cursor by the given offset

Parameters

Name Type Description
it NumberIterator<N>& NumberIterator
offset N Offset

operator-=

Spice
public inline p operator-=<N>(NumberIterator<N>& it, N offset)

Move the cursor back by the given offset

Parameters

Name Type Description
it NumberIterator<N>& NumberIterator
offset N Offset