DMD 0.161 release

BCS BCS at pathlink.com
Wed Jun 21 10:39:00 PDT 2006


Walter Bright wrote:
> xs0 wrote:
> 
>> Walter Bright wrote:
>>
>>> 85: It can't be made to work, because an interface handle is 
>>> different from a class handle. It doesn't work in C++, either, for 
>>> the same reasons.
>>
>>
>> But it can be made to work, because an interface handle could be the 
>> same as a class handle. It works that way in Java, and is _far_ more 
>> useful, even if performance of method calls is reduced slightly.
>>
>> But we talked about that already, and I don't suppose you'll change 
>> your mind this time..
> 
> 
> Java makes it "work" by doing runtime manipulation of interface/class 
> handles whenever they are used. This is too inefficient for a native 
> compiled language.
> 
> Consider this:
> 
>   int can be implicitly converted to long.
>   Therefore, shouldn't int[] be usable as a long[]?
> 
> It's an exactly analogous situation.


A user code solution could be used:

T[] castArray(F, T)(F[] array)
{
	T[] ret = new T[array.length];
	foreach(i,e;array)
	{
			// this is from memory, but you get the picture
		static if(is(T : Object))
			(e!is null) ? ret[i]=e; ? ret[i]=null;
		else
			ret[i]=e;
	}
	return ret;
}


void main()
{
	const static int[] from = [1,2,3,4,5,6,7,8,9];

	long[] to = castArray!(int, long)(from);
}



More information about the Digitalmars-d-announce mailing list