View source code
Display the source code in std/range/primitives.d from which this page was generated on
github.
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.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.range.primitives.put
Outputs
to e
. The exact effect is dependent upon the two
types. Several cases are accepted, as described below. The code snippets
are attempted in order, and the first to compile "wins" and gets
evaluated.
r
In this table "doPut" is a method that places
into e
, using the
correct primitive: r
r.put(
if e
)R
defines
, put
r.front =
if e
is an input range (followed by r
r.popFront()
), or
otherwise.
r
(e
)
Code Snippet | Scenario |
---|---|
r.doPut( |
R specifically accepts an E . |
r.doPut([ |
R specifically accepts an E[] . |
r.putChar( |
R accepts some form of string or character. put will
transcode the character accordingly. |
for (; !e.empty; e.popFront()) |
Copying range E into R . |
Copying range E into R . |
Prototype
void put(R, E)( R r, E e );
Tip
should not be used "UFCS-style", e.g. put
r.put(
.
Doing this may call e
)R.put
directly, by-passing any transformation
feature provided by Range.put
.
is prefered.
put
(r
, e
)
Example
int[] r = new int[](4); static assert(isInputRange!(int[])); static assert( isNativeOutputRange!(int[], int)); static assert(!isNativeOutputRange!(int[], int[])); static assert( isOutputRange!(int[], int[])); if (!r.empty) put(r, 1); //guaranteed to succeed if (!r.empty) put(r, [1, 2]); //May actually error out.
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.