replicate

  1. ElementEncodingType!S[] replicate(S s, size_t n)
    replicate
    (
    S
    )
    (
    S s
    ,
    size_t n
    )
  2. ElementType!S[] replicate(S s, size_t n)

Parameters

s S

an input range or a dynamic array

n size_t

number of times to repeat s

Return Value

Type: ElementEncodingType!S[]

An array that consists of s repeated n times. This function allocates, fills, and returns a new array.

Examples

auto a = "abc";
auto s = replicate(a, 3);

assert(s == "abcabcabc");

auto b = [1, 2, 3];
auto c = replicate(b, 3);

assert(c == [1, 2, 3, 1, 2, 3, 1, 2, 3]);

auto d = replicate(b, 0);

assert(d == []);

See Also

For a lazy version, refer to std.range.repeat.

Meta