D Language Ranges

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


If a foreach is encountered by the compiler

foreach (element; range) {

it's internally rewritten similar to the following:

for (auto it = range; !it.empty; it.popFront()) {
    auto element = it.front;

Any object which fulfills the above interface is called an input range and is thus a type that can be iterated over:

struct InputRange {
    @property bool empty();
    @property T front();
    void popFront();

Got any D Language Question?