View source code
Display the source code in std/range.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.takeExactly
Similar to take, but assumes that has at least range elements. Consequently, the result of n
always defines the takeExactly(range, n)length property (and initializes it to )
even when n itself does not define rangelength.
The result of is identical to that of takeExactlytake in
cases where the original range defines length or is infinite.
Unlike take, however, it is illegal to pass a range with less than
elements to n; this will cause an assertion failure.
takeExactly
Prototype
auto takeExactly(R)( R range, size_t n ) if (isInputRange!R);
Example
import std.algorithm : equal; auto a = [ 1, 2, 3, 4, 5 ]; auto b = takeExactly(a, 3); assert(equal(b, [1, 2, 3])); static assert(is(typeof(b.length) == size_t)); assert(b.length == 3); assert(b.front == 1); assert(b.back == 3);
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.