Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

d language
communitycreator

What is the fill() in D language?

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

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.

Syntax

fill(range, filler_value)

Parameter

  • 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.

Return value

Returns an input range that has been filled with the indicated values.

Code

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]
}

Explanation

  • Lines 2–3: We import some modules to call some functions for our code.
  • Lines 5–13: We start the primary function and end it.
  • Lines 7–8: We declare some variables.
  • Line 10: We call the fill() method to carry out the fill operation.
  • Line 12: We display the result of the operation.

RELATED TAGS

d language
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring