Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

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 usinga local clone.

std.range.interfaces

This module is a submodule ofstd.range.
The mainstd.range module provides template-based tools for working withranges, but sometimes an object-based interface for ranges is needed, such aswhen runtime polymorphism is required. For this purpose, this submoduleprovides a number of object andinterface definitions that can be used towrap around range objects created by thestd.range templates.
InputRangeWrapper for input ranges.
InputAssignableWrapper for input ranges with assignable elements.
ForwardRangeWrapper for forward ranges.
ForwardAssignableWrapper for forward ranges with assignable elements.
BidirectionalRangeWrapper for bidirectional ranges.
BidirectionalAssignableWrapper for bidirectional ranges with assignable elements.
RandomAccessFiniteWrapper for finite random-access ranges.
RandomFiniteAssignableWrapper for finite random-access ranges with assignable elements.
RandomAccessInfiniteWrapper for infinite random-access ranges.
OutputRangeWrapper for output ranges.
OutputRangeObjectClass that implements theOutputRange interface and wraps theput methods in virtual functions.
outputRangeObjectConvenience function for creating anOutputRangeObject with a base range of type R that accepts types E.
InputRangeObjectClass that implements theInputRange interface and wraps the input range methods in virtual functions.
inputRangeObjectConvenience function for creating anInputRangeObject of the proper type.
MostDerivedInputRangeReturns the interface type that best matches the range.

Sourcestd/range/interfaces.d

License:
Boost License 1.0.
Authors:
Andrei Alexandrescu, David Simcha, andJonathan M Davis. Credit for some of the ideas in building this module goes toLeonardo Maffi.
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 thatisInputRange and friends check for conformance to structural interfaces not for implementation of theseinterface types.

LimitationsThese interfaces are not capable of forwardingref 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:
Examples:
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);
@property Efront();
EmoveFront();
Callsstd.range.primitives.moveFront on the wrapped range, if possible. Otherwise, throws anUnsupportedRangeMethod exception.
voidpopFront();
@property boolempty();
intopApply(scope int delegate(E));

intopApply(scope int delegate(size_t, E));
foreach iteration uses opApply, since one delegate call per loop iteration is faster than three virtual function calls.
interfaceForwardRange(E): InputRange!E;
Interface for a forward range of typeE.
@property ForwardRange!Esave();
interfaceBidirectionalRange(E): ForwardRange!E;
Interface for a bidirectional range of typeE.
@property BidirectionalRange!Esave();
@property Eback();
EmoveBack();
Callsstd.range.primitives.moveBack on the wrapped range, if possible. Otherwise, throws anUnsupportedRangeMethod exception
voidpopBack();
interfaceRandomAccessFinite(E): BidirectionalRange!E;
Interface for a finite random access range of typeE.
@property RandomAccessFinite!Esave();
EopIndex(size_t);
EmoveAt(size_t);
@property size_tlength();
aliasopDollar = length;
RandomAccessFinite!EopSlice(size_t, size_t);
interfaceRandomAccessInfinite(E): ForwardRange!E;
Interface for an infinite random access range of typeE.
enum boolempty;
EmoveAt(size_t);
Callsstd.range.primitives.moveAt on the wrapped range, if possible. Otherwise, throws anUnsupportedRangeMethod exception.
@property RandomAccessInfinite!Esave();
EopIndex(size_t);
interfaceInputAssignable(E): InputRange!E;
Adds assignable elements to InputRange.
@property voidfront(EnewVal);
interfaceForwardAssignable(E): InputAssignable!E, ForwardRange!E;
Adds assignable elements to ForwardRange.
@property ForwardAssignable!Esave();
interfaceBidirectionalAssignable(E): ForwardAssignable!E, BidirectionalRange!E;
Adds assignable elements to BidirectionalRange.
@property BidirectionalAssignable!Esave();
@property voidback(EnewVal);
interfaceRandomFiniteAssignable(E): RandomAccessFinite!E, BidirectionalAssignable!E;
Adds assignable elements to RandomAccessFinite.
@property RandomFiniteAssignable!Esave();
voidopIndexAssign(Eval, size_tindex);
interfaceOutputRange(E);
Interface for an output range of typeE. Usage is similar to theInputRange interface and descendants.
voidput(E);
classOutputRangeObject(R, E...): staticMap!(OutputRange, E);
Implements theOutputRange interface for all types E and wraps theput method for each typeE in a virtual function.
this(Rrange);
templateMostDerivedInputRange(R) if (isInputRange!(Unqual!R))
Returns the interface type that best matchesR.
templateInputRangeObject(R) if (isInputRange!(Unqual!R))
Implements the most derived interface thatR works with and wraps all relevant range primitives in virtual functions. IfR is already derived from theInputRange interface, aliases itself away.
InputRangeObject!RinputRangeObject(R)(Rrange)
if (isInputRange!R);
Convenience function for creating anInputRangeObject of the proper type. SeeInputRange for an example.
templateoutputRangeObject(E...)
Convenience function for creating anOutputRangeObject with a base range of typeR that accepts typesE.
Examples:
import std.array;auto app = appender!(uint[])();auto appWrapped =outputRangeObject!(uint,uint[])(app);staticassert(is(typeof(appWrapped) : OutputRange!(uint[])));staticassert(is(typeof(appWrapped) : OutputRange!(uint)));
OutputRangeObject!(R, E)outputRangeObject(R)(Rrange);
classUnsupportedRangeMethod:object.Exception;
Thrown when an interface method is not supported by the wrapped range
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Sat Feb 21 00:07:42 2026

[8]ページ先頭

©2009-2026 Movatter.jp