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.
InputRange | Wrapper for input ranges. |
InputAssignable | Wrapper for input ranges with assignable elements. |
ForwardRange | Wrapper for forward ranges. |
ForwardAssignable | Wrapper for forward ranges with assignable elements. |
BidirectionalRange | Wrapper for bidirectional ranges. |
BidirectionalAssignable | Wrapper for bidirectional ranges with assignable elements. |
RandomAccessFinite | Wrapper for finite random-access ranges. |
RandomAccessAssignable | Wrapper for finite random-access ranges with assignable elements. |
RandomAccessInfinite | Wrapper for infinite random-access ranges. |
OutputRange | Wrapper for output ranges. |
OutputRangeObject | Class that implements the OutputRange interface and wraps the put methods in virtual functions. |
outputRangeObject | Convenience function for creating an OutputRangeObject with a base range of type R that accepts types E. |
InputRangeObject | Class that implements the InputRange interface and wraps the input range methods in virtual functions. |
inputRangeObject | Convenience function for creating an InputRangeObject of the proper type. |
MostDerivedInputRange | Returns the interface type that best matches the range. |
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.
ref
access to elements. inputRangeObject
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);
foreach
iteration uses opApply, since one delegate call per loop iteration is faster than three virtual function calls.
Interface for a forward range of type E
.
Interface for a bidirectional range of type E
.
Interface for a finite random access range of type E
.
Interface for an infinite random access range of type E
.
Adds assignable elements to InputRange.
Adds assignable elements to ForwardRange.
Adds assignable elements to BidirectionalRange.
Adds assignable elements to RandomAccessFinite.
Interface for an output range of type E
. Usage is similar to the InputRange
interface and descendants.
Implements the OutputRange
interface for all types E and wraps the put
method for each type E
in a virtual function.
Returns the interface type that best matches 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.
Convenience function for creating an InputRangeObject
of the proper type. See InputRange
for an example.
Convenience function for creating an OutputRangeObject
with a base range of type R
that accepts types E
.
import std.array; auto app = appender!(uint[])(); auto appWrapped = outputRangeObject!(uint, uint[])(app); static assert(is(typeof(appWrapped) : OutputRange!(uint[]))); static assert(is(typeof(appWrapped) : OutputRange!(uint)));
© 1999–2019 The D Language Foundation
Licensed under the Boost License 1.0.
https://dlang.org/phobos/std_range_interfaces.html