How does one cast to an array type?

Vinay Sajip vinay_sajip at yahoo.co.uk
Thu Oct 17 12:19:03 UTC 2019


Are arrays and objects part of a unified type system? 
Specifically, if I do

void foo(Object x) {
     if (typeid(x) == typeid(Object[])) {
         auto a = cast(Object[]) x;
     }
}

I get a compilation error:

onlineapp.d(3): Error: cannot cast expression x of type 
object.Object to Object[]

What's the way to achieve the cast, which should be safe given 
the typeid check?

Thanks and regards,

Vinay Sajip


More information about the Digitalmars-d-learn mailing list