Hi, all!

Try this:

---< snip >---

void remove(T)(out T[] array,T element) {
  int r=0,w=0;
  while (r<array.length) {
    if (array[r]!=element)
      array[w++]=array[r];
    ++r;
  }
  array.length=w;
}

void test() {
  int[] array;
  int element=2;
  //
  array=[1,3,2,2,1,3,1,1,2];
  writef("direct\n");
  writef("  before : ",array,"\n");
  int r=0,w=0;
  while (r<array.length) {
    if (array[r]!=element)
      array[w++]=array[r];
    ++r;
  }
  array.length=w;
  writef("  after  : ",array,"\n");
  //
  array=[1,3,2,2,1,3,1,1,2];
  writef("template\n");
  writef("  before : ",array,"\n");
  remove!(int)(array,element);
  writef("  after  : ",array,"\n");
}

---< snap >---

I get the following output:

direct
  before : [1,3,2,2,1,3,1,1,2]
  after  : [1,3,1,3,1,1]
template
  before : [1,3,2,2,1,3,1,1,2]
  after  : []

So, my question is: Huh?

Kind regards.



Reply via email to