auto arr = [1, 2, 3, 4, 2, 3]; assert(arr.replaceInPlace(2, 7) == [1, 7, 3, 4, 2, 3]); // The input array gets modified. assert(arr == [1, 7, 3, 4, 2, 3]); // Replaces only the first occurrence assert(arr.replaceInPlace(2, 7) == [1, 7, 3, 4, 7, 3]); // Can be called with non-lvalues assert([1, 2, 3].replaceInPlace(2, 7) == [1, 7, 3]);
Replaces the first occurrence of needle by replacement in array if present. Modifies array.