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 e to r. 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.

In this table "doPut" is a method that places e into r, using the correct primitive: r.put(e) if R defines put, r.front = e if r is an input range (followed by r.popFront()), or r(e) otherwise.

e.front);
Code Snippet Scenario
r.doPut(e); R specifically accepts an E.
r.doPut([ e ]); R specifically accepts an E[].
r.putChar(e); R accepts some form of string or character. put will transcode the character e accordingly.
for (; !e.empty; e.popFront()) put(r, e.front); Copying range E into R.
Copying range E into R.

Prototype

void put(R, E)(
  R r,
  E e
);

Tip

put should not be used "UFCS-style", e.g. r.put(e). Doing this may call R.put directly, by-passing any transformation feature provided by Range.put. put(r, e) is prefered.

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.

License

Boost License 1.0.

Comments