Problem with type-casting to interface arrays

Daniel Keep daniel.keep.lists at gmail.com
Tue Mar 20 17:13:21 PDT 2007



Vladimir Panteleev wrote:
> On Tue, 20 Mar 2007 08:29:55 +0200, Lionello Lunesu <lio at lunesu.remove.com> wrote:
> 
>> Maybe it would be a good idea to add a separate cast expression for
>> reinterpret_cast. The cast(..) can do anything from a C-cast to
>> dynamic_cast to static_cast to reinterpret_cast. All the safe casts can
>> use cast(..) but I think that for conversions without any link between
>> the two types, it would be better to introduce some new cast
>> syntax/keyword.. cast!(..)? :)
> 
> I agree. Imagine the mess this could accidentally cause in templates.

U[] arrcast(U, T)(T[] arr)
{
    U[] result;
    result.length = arr.length;
    foreach( i, a ; arr )
        result[i] = cast(U)a;
    return result;
}

...

I[] i = arrcast!(I)(c);

...

We don't need no op-er-a-tor!
Hey!  You guys!  Leave poor cast() alone!
All in all it's just a 'nother tem-plated call.

:3

	-- Daniel

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list