takeExactly

Take exactly n element from range. Throws an exception if range has not enough elements.

ElementType!R[n]
takeExactly
(
size_t n
R
)
()
if (
isInputRange!R
)

Throws

Exception if range has less than n elements.

Examples

import std.exception : assertThrown;
import std.range : iota;

static assert(is(typeof(iota(10).takeExactly!5) == int[5]));
assert(iota(10).takeExactly!5 == [0, 1, 2, 3, 4]);

assertThrown!Exception(iota(2).takeExactly!5);

Meta