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

1 import std.exception : assertThrown;
2 import std.range : iota;
3 
4 static assert(is(typeof(iota(10).takeExactly!5) == int[5]));
5 assert(iota(10).takeExactly!5 == [0, 1, 2, 3, 4]);
6 
7 assertThrown!Exception(iota(2).takeExactly!5);

Meta