The fill()
method is built into the D language. It helps fill a D tuple or range value with a provided value. It does this by assigning values to each element of the input range.
We can use a range or a single value as the filler value. We may also use a range of values, instead of repeatedly using a single value to replace each input range value.
fill(range, filler_value)
range
: This is the input range which will be filled with new values replacing its old content. It can’t be empty.
filler_value
:This is the value assigned to each of the range member.
Returns an input range that has been filled with the indicated values.
The code snippet below contains some variables used to perform the fill()
operation.
import std.algorithm.mutation;import std.stdio: write, writeln, writef, writefln;void main() {int[] a = [ 2, 5, 7, 9, 10 ];int[] b = [ 4, 1 ];fill(a, b);writeln(a); // [4, 1, 4, 1, 4]}
fill()
method to carry out the fill operation.