View source code
Display the source code in std/range/interfaces.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Interface std.range.interfaces.InputRange

These interfaces are intended to provide virtual function-based wrappers around input ranges with element type E. This is useful where a well-defined binary interface is required, such as when a DLL function or virtual function needs to accept a generic range as a parameter. Note that isInputRange and friends check for conformance to structural interfaces not for implementation of these interface types.

interface InputRange(E) ;

Properties

NameTypeDescription
empty[get] bool
front[get] E

Methods

NameDescription
moveFront () Calls moveFront on the wrapped range, if possible. Otherwise, throws an UnsupportedRangeMethod exception.
opApply () foreach iteration uses opApply, since one delegate call per loop iteration is faster than three virtual function calls.
popFront ()

Limitations

These interfaces are not capable of forwarding ref access to elements.

Infiniteness of the wrapped range is not propagated.

Length is not propagated in the case of non-random access ranges.

See Also

inputRangeObject

Example

import std.algorithm.iteration : map;
import std.range : iota;

void useRange(InputRange!int range) {
    // Function body.
}

// Create a range type.
auto squares = map!"a * a"(iota(10));

// Wrap it in an interface.
auto squaresWrapped = inputRangeObject(squares);

// Use it.
useRange(squaresWrapped);

Authors

Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.

License

Boost License 1.0.