To what extent the source object should overwrite set (non-init) values in the receiving object.
Array to meld (source).
Reference to the array to meld (target).
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);
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.