DMD 0.161 release

Roberto Mariottini Roberto_member at pathlink.com
Thu Jun 22 00:47:08 PDT 2006


In article <e7bv51$9lp$1 at digitaldaemon.com>, Walter Bright says...

[...]
>Consider this:
>
>   int can be implicitly converted to long.
>   Therefore, shouldn't int[] be usable as a long[]?
>
>It's an exactly analogous situation.

I agree.
To make it simple you can do like this:

template copycast (T : T[])
{
  T[] copycast (X) (X[] array) 
  {
    T[] retVal = new T[array.length];
    foreach (int i, X elem; array)
    {
      retVal[i] = cast(T) elem;
    }
    return retVal;
  }
}
 
int main()
{
  int[] a = new int[10];
  long[] al = copycast!(long[]) (a);
 
  interface I {  }
  class A : I {  }
  A[] array = new A[10];
  I[] dest = copycast!(I[]) (array);
 
  return 0;
}

Ciao

---
http://www.mariottini.net/roberto/



More information about the Digitalmars-d-announce mailing list