The OpenD Programming Language

dropBackExactly

Similar to drop and dropBack but they call range.$(LREF popFrontExactly)(n) and range.popBackExactly(n) instead.

Note: Unlike drop, dropExactly will assume that the range holds at least n elements. This makes dropExactly faster than drop, but it also means that if range does not contain at least n elements, it will attempt to call popFront on an empty range, which is undefined behavior. So, only use popFrontExactly when it is guaranteed that range holds at least n elements.

R
dropBackExactly
(
R
)
(,
size_t n
)
if (
isBidirectionalRange!R
)

Parameters

range R

the input range to drop from

n size_t

the number of elements to drop

Return Value

Type: R

range with n elements dropped

Examples

import std.algorithm.comparison : equal;
import std.algorithm.iteration : filterBidirectional;

auto a = [1, 2, 3];
assert(a.dropExactly(2) == [3]);
assert(a.dropBackExactly(2) == [1]);

string s = "日本語";
assert(s.dropExactly(2) == "語");
assert(s.dropBackExactly(2) == "日");

auto bd = filterBidirectional!"true"([1, 2, 3]);
assert(bd.dropExactly(2).equal([3]));
assert(bd.dropBackExactly(2).equal([1]));

See Also

Meta