meldInto

Takes two arrays and melds them together, making a union of the two.

It only overwrites members that are T.init, so only unset fields get their values overwritten by the melding array. Supply a template parameter MeldingStrategy.aggressive to make it overwrite if the melding array's field is not T.init. Furthermore use MeldingStrategy.overwriting if working with bool members.

  1. void meldInto(QualThing meldThis, Thing intoThis)
  2. void meldInto(Array1 meldThis, Array2 intoThis)
    pure nothrow
    void
    meldInto
    ()
    (
    auto ref Array1 meldThis
    ,
    ref Array2 intoThis
    )
    if (
    isMerelyArray!Array1 &&
    &&
    isMutable!Array2
    )
  3. void meldInto(QualAA meldThis, AA intoThis)

Parameters

strategy

To what extent the source object should overwrite set (non-init) values in the receiving object.

meldThis Array1

Array to meld (source).

intoThis Array2

Reference to the array to meld (target).

Examples

int[] arr1 = [ 1, 2, 3, 0, 0, 0 ];
int[] arr2 = [ 0, 0, 0, 4, 5, 6 ];
arr1.meldInto!(MeldingStrategy.conservative)(arr2);

assert(arr2 == [ 1, 2, 3, 4, 5, 6 ]);
import std.conv : to;

auto arr1 = [ 123, 0, 789, 0, 456, 0 ];
auto arr2 = [ 0, 456, 0, 123, 0, 789 ];
arr1.meldInto!(MeldingStrategy.conservative)(arr2);
assert((arr2 == [ 123, 456, 789, 123, 456, 789 ]), arr2.to!string);

auto yarr1 = [ 'Z', char.init, 'Z', char.init, 'Z' ];
auto yarr2 = [ 'A', 'B', 'C', 'D', 'E', 'F' ];
yarr1.meldInto!(MeldingStrategy.aggressive)(yarr2);
assert((yarr2 == [ 'Z', 'B', 'Z', 'D', 'Z', 'F' ]), yarr2.to!string);

auto harr1 = [ char.init, 'X' ];
yarr1.meldInto(harr1);
assert((harr1 == [ 'Z', 'X', 'Z', char.init, 'Z' ]), harr1.to!string);

char[5] harr2 = [ '1', '2', '3', '4', '5' ];
char[] harr3;
harr2.meldInto(harr3);
assert((harr2 == harr3), harr3.to!string);

int[3] asdf;
int[3] hasdf;
asdf.meldInto(hasdf);

int[] dyn = new int[2];
int[3] stat;
dyn.meldInto(stat);

Meta