auto a = Array!int([10,20,30,40,50]); /* Iterate over an Array. If `remove` is set inside the loop body, the current element is removed from the array. This is more efficient than multiple calls to the `.remove()` method. */ foreach(i, ref x, ref bool rem; prune(a)) { if(x == 30) x = 31; rem = (i == 1) || (x == 40); } assert(equal(a[], [10,31,50])); /** same, but without indices */ foreach(ref x, ref bool rem; prune(a)) { if(x == 10) x = 11; rem = (x == 50); } assert(equal(a[], [11,31]));