On Thursday, 17 October 2019 at 12:19:03 UTC, Vinay Sajip wrote:
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
Did you try templates? It seems easier:
https://run.dlang.io/is/BbkTCw
Andrea