Extract typeinfo

Namespace rswhite4 at googlemail.com
Wed Mar 5 14:41:16 PST 2014


On Wednesday, 5 March 2014 at 19:21:39 UTC, Adam D. Ruppe wrote:
> On Wednesday, 5 March 2014 at 19:15:12 UTC, Namespace wrote:
>> Is there a way to extract the correct typeinfo of an array if 
>> I only have the pointer?
>
> Nope, typeinfos are only stored in runtime on classes. All 
> other types get it only through the static info.
>
> Consider the following:
>
> char[10] a;
>
> char[] b = a[3..5];// from the middle of it
>
> void* c = b.ptr;
>
>
> Even if the info was stored with a, the slice would have no 
> idea where to find it, so you couldn't get it from the pointer 
> either.
>
>
> The way druntime does it with void pointers is to pass the 
> typeinfo too:
>
> void useArray(void[] a, TypeInfo a_type);

Ah thank you. :)


More information about the Digitalmars-d-learn mailing list