IntegerRange
Stores one compiler-constructed fixed-width integer progression.
Module std.iteration
import std.iteration;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
IntegerRange
pub struct IntegerRange<T>Stores one compiler-constructed fixed-width integer progression.
Range syntax evaluates start, end, and optional step exactly once and creates this opaque allocation-free value. The compiler preserves signed direction, endpoint inclusion, and no-overflow termination semantics.
T: Fixed-width integer element type selected by the compiler's range expression.
Example
module example.integer_range;
fn Main() -> i32 {
let Range = 0_i32..=5_i32 by 2_i32;
var Cursor = Range.CreateIterator();
var Sum = 0;
loop {
switch Cursor.Next() {
case .Some { Value = Item } => Sum += Item;
case .None => break;
}
}
return Sum - 6;
}IntegerRange.CreateIterator
pub readonly fn CreateIterator() -> IntegerRangeIterator<T>Creates an independent cursor at the progression's first test. Return: Allocation-free cursor borrowing no external owner.
IntegerRangeIterator
pub struct IntegerRangeIterator<T>Owns traversal state for one fixed-width integer progression.
The opaque cursor is produced only from IntegerRange<T> and cannot expose a wrapping or out-of-range sentinel. T: Fixed-width integer element type of the originating IntegerRange<T> progression.
IntegerRangeIterator.Next
pub fn Next() -> T?Tests, yields, and advances once without overflowing T. Return: The next progression value or none after endpoint crossing.