std.range.interfaces

This module is a submodule of std.range.

The main std.range module provides template-based tools for working with ranges, but sometimes an object-based interface for ranges is needed, such as when runtime polymorphism is required. For this purpose, this submodule provides a number of object and interface definitions that can be used to wrap around range objects created by the std.range templates.

Source: std/range/interfaces.d

License

Boost License 1.0.

Authors

Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas

in building this module goes to

Leonardo Maffi.

Types 12

interfaceInputRange(E)

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.

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

Methods
E front() @property
E moveFront()Calls moveFront on the wrapped range, if possible. Otherwise, throws an UnsupportedRangeMethod exception.
void popFront()
bool empty() @property
int opApply(scope int delegate(E))`foreach` iteration uses opApply, since one delegate call per loop iteration is faster than three virtual function calls.
int opApply(scope int delegate(size_t, E))Ditto
interfaceForwardRange(E) : InputRange!E

Interface for a forward range of type E.

Methods
ForwardRange!E save() @property

Interface for a bidirectional range of type E.

Methods
BidirectionalRange!E save() @property
E back() @property
E moveBack()Calls moveBack on the wrapped range, if possible. Otherwise, throws an UnsupportedRangeMethod exception
void popBack()

Interface for a finite random access range of type E.

Methods
RandomAccessFinite!E save() @property
E opIndex(size_t)
E moveAt(size_t)
size_t length() @property

Interface for an infinite random access range of type E.

Fields
bool empty
Methods
E moveAt(size_t)Calls moveAt on the wrapped range, if possible. Otherwise, throws an UnsupportedRangeMethod exception.
E opIndex(size_t)
interfaceInputAssignable(E) : InputRange!E

Adds assignable elements to InputRange.

Methods
void front(E newVal) @property

Adds assignable elements to ForwardRange.

Methods
ForwardAssignable!E save() @property

Adds assignable elements to BidirectionalRange.

Methods
void back(E newVal) @property

Adds assignable elements to RandomAccessFinite.

Methods
void opIndexAssign(E val, size_t index)
interfaceOutputRange(E)

Interface for an output range of type E. Usage is similar to the InputRange interface and descendants.

Methods
void put(E)
classOutputRangeObject(R, E...) : staticMap!(OutputRange, E)

Implements the OutputRange interface for all types E and wraps the put method for each type E in a virtual function.

Fields
private R _range
Constructors
this(R range)
classUnsupportedRangeMethod : Exception

Thrown when an interface method is not supported by the wrapped range

Functions 2

private fnstring putMethods(E...)()
fnInputRangeObject!R inputRangeObject(R)(R range) if (isInputRange!R)Convenience function for creating an `InputRangeObject` of the proper type. See InputRange for an example.

Templates 3

tmplMostDerivedInputRange(R) if (isInputRange!(Unqual!R))

Returns the interface type that best matches R.

tmplInputRangeObject(R) if (isInputRange!(Unqual!R))

Implements the most derived interface that R works with and wraps all relevant range primitives in virtual functions. If R is already derived from the InputRange interface, aliases itself away.

tmploutputRangeObject(E...)

Convenience function for creating an OutputRangeObject with a base range of type R that accepts types E.

Functions
OutputRangeObject!(R, E) outputRangeObject(R)(R range)