Search⌘ K

InputRange

Explore the InputRange type in D programming to understand how to iterate over elements sequentially. Learn to implement empty, front, and popFront functions to create custom ranges like the School type, enabling seamless integration with algorithms that operate on InputRange types.

We'll cover the following...

Introduction

This type of range models the type of iteration where elements are accessed in sequence, as you have seen in the print() functions above. Most algorithms only require that elements are iterated in the forward direction without needing to look at elements that have already been iterated over. InputRange also models the standard input streams of programs, where elements are removed from the stream as they are read.

For completeness, here are the three functions that InputRange requires:

  • empty: specifies whether the range is empty; it must return true when the range is considered to be empty and false otherwise

  • front: provides access to the element at the beginning of the range

  • ...