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 arr1 = [ 'Z', char.init, 'Z', char.init, 'Z' ]; auto arr2 = [ 'A', 'B', 'C', 'D', 'E', 'F' ]; arr1.meldInto!(MeldingStrategy.aggressive)(arr2); assert((arr2 == [ 'Z', 'B', 'Z', 'D', 'Z', 'F' ]), arr2.to!string); auto arr3 = [ char.init, 'X' ]; arr1.meldInto(arr3); assert((arr3 == [ 'Z', 'X', 'Z', char.init, 'Z' ]), arr3.to!string); } { char[5] arr1 = [ '1', '2', '3', '4', '5' ]; char[] arr2; arr1.meldInto(arr2); assert((arr1 == arr2), arr2.to!string); } { int[3] arr1 = [ 1, 0, 3 ]; int[3] arr2 = [ 0, 2, 0 ]; arr1.meldInto(arr2); assert((arr2 == [ 1, 2, 3 ]), arr2.to!string); } { int[] dyn = new int[3]; int[4] stat = [ 9, 2, 0, 4 ]; dyn = [ 1, 0, 3 ]; dyn.meldInto!(MeldingStrategy.conservative)(stat); assert((stat == [ 9, 2, 3, 4 ]), stat.to!string); }
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.