The OpenD Programming Language

padRight

Extend the length of the input range r by padding out the end of the range with the element e. The element e must be of a common type with the element type of the range r as defined by std.traits.CommonType. If n is less than the length of of r, then the contents of r are returned.

The range primitives that the resulting range provides depends whether or not r provides them. Except the functions back and popBack, which also require the range to have a length as well as back and popBack

padRight
(
R
E
)
(
R r
,
E e
,
size_t n
)
if (
!is(CommonType!(ElementType!R, E) == void)
)

Parameters

r R

an input range with a length

e E

element to pad the range with

n size_t

the length to pad to

Return Value

Type: auto

A range containing the elements of the original range with the extra padding

See Also: std.string.rightJustifier

Examples

import std.algorithm.comparison : equal;

assert([1, 2, 3, 4].padRight(0, 6).equal([1, 2, 3, 4, 0, 0]));
assert([1, 2, 3, 4].padRight(0, 4).equal([1, 2, 3, 4]));

assert("abc".padRight('_', 6).equal("abc___"));

Meta