D Programming Language 2.0

Last update Wed Jun 9 17:54:33 2010


This module is a port of a growing fragment of the algorithm header in Alexander Stepanov's Standard Template Library.

For now only iterators for built-in arrays are defined. Built-in arrays are also considered ranges themselves. The iterator of a built-in array T[] is a pointer of type T*. This may change in the future.

Boost License 1.0.

Andrei Alexandrescu

Copyright Andrei Alexandrescu 2008 - 2009. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at ) http:

template Iterator(Range : T[],T)
Iterator!(Range) or Iterator!(Collection) is the type that is able to iterate an object of type Range or Collection, respectively. This defines Iterator!(T[]) to be T* for all types T.

template ElementType(Range : T[],T)
The element type of a range. For a built-in array T[], the element type is T.

bool isEmpty(T)(T[] r);
Returns true if and only if the range r is empty.

Iterator!(T[]) begin(T)(T[] r);
Returns an iterator to the beginning of the range r.

Iterator!(T[]) end(T)(T[] r);
Returns an iterator just past the end of the range r.

ElementType!(T[]) front(T)(T[] r);
Returns the front element of the range.


T[] range(T)(T* first, T* last);
Creates a range from a pair of iterators.

last must be reachable from first (for pointers, both must belong to the same memory chunk and last >= first).

struct Retro(R : E[],E);
Type that reverses the iteration order of a range.

Retro!(E[]) retro(E)(E[] r);
Returns a range that iterates r backwards.

Iterator!(Retro!(F[])) rBegin(F)(F[] range);
Returns begin(retro(range)).

Iterator!(Retro!(F[])) rEnd(F)(F[] range);
Returns end(retro(range)).