On Thursday, 9 February 2012 at 12:51:09 UTC, Pedro Lacerda wrote:
I __believe__ that insertInPlace doesn't shift the elements,
Yes, It appears that it really doesn't shift the array,
insertInPlace just returns a new array with a new element in n
position.
Maybe this function do what you want.
int[] arr = [0,1,2,3,4,5,6,7,8,9];
void maybe(T)(T[] arr, size_t pos, T value) {
size_t i;
for (i = arr.length - 1; i > pos; i--) {
arr[i] = arr[i-1];
}
arr[i] = value;
}
In fact, I usually wrote functions as you did. I just looking for
a new way to do that with D and Phobos lib.
Thanks,
Matheus.