The moveSome()
function in the D language is part of the std.algorithm.mutation
module.
This function moves some value from a tuple value into another tuple value. It does this by simply making a copy of the value in a tuple and storing it inside another tuple.
Let’s suppose we have two tuples, A
and B
, and wish to move some values of A
into B
. We can do this using the moveSome()
function. The tuple A
tuple retains its value, but B
now contains a copy of all or some values of A
in it.
If the length of B
is less than that of A
, the moveSome()
function returns the leftover values of A
after the copy.
moveSome(source,target)
source
: This is the tuple value from which we create a copy. Some or all of the values will be copied and moved into another tuple.
target
: This contains the values that will be moved.
The moveSome()
function returns the leftovers of source
after the copy if the length of target
is less than that of source
.
import std.algorithm.mutation;import std.stdio: write, writeln, writef, writefln;void main(){// Declare integer arrays.int[5] alm = [ 1, 2, 3, 4, 5 ];int[3] balm ;// Declare string arrays.string[5] calm = [ "week","young","scala","house","rippen" ];string[3] palm;//Move some of alm into balm. Move as much as the length of balmmoveSome(alm[], balm[]);//Move some of calm into balm. Move as much as the length of palmmoveSome(calm[], palm[]);writeln(alm[]); // [1, 2, 3, 4, 5] After the move, the value of alm is still the same.writeln(balm); // [1, 2, 3, 4, 5]writeln(palm); // ["week", "young", "scala"]}
moveSome()
function to move some of alm
into balm
. We move as much as the length of the balm
array.moveSome()
function to move some of the calm
values into palm
. We move as much as the length of the palm
array.