Going from TypeInfo of template to TypeInfo of template parameter/member
Bill Baxter
dnewsgroup at billbaxter.com
Mon Nov 12 18:02:41 PST 2007
Christopher Wright wrote:
> Bill Baxter wrote:
>> I'm trying to get info about types from their TypeInfo.
>>
>> Say I have a struct like
>>
>> struct Container(T)
>> {
>> T[] elems;
>> }
>>
>> And I have a TypeInfo for a Container!(float). Is there any way to
>> get the TypeInfo for a float out of that? Or a double, or int, or
>> whatever it happens to be.
>>
>> TypeInfo get_container_element_type(TypeInfo container_typeinfo)
>> {
>> ???
>> }
>>
>> The TypeInfo's .next and .offTi are both null, so that's no help.
>> The toString includes the stringized version of the type "float",
>> though, so I could try to use that. Seems unreliable though.
>>
>> Thanks for any suggestions.
>> --bb
>
> Looks like everyone's doing the same things these days :)
>
> My post a bit above yours is asking essentially the same question for
> classes and interfaces, so I'd guess there's no way to do that at
> compile time, and therefore probably no way to do that at runtime, in
> the general case.
I'm not seeing the one you're talking about. You mean the one that was
answered by using if(is(x==interface)) ?
> If you only need it at runtime, you could do something like:
>
> struct Container(T) {
> static TypeInfo containedType = typeid(T);
> //...
> }
>
> That assumes you're only dealing with code that you wrote.
It is code I wrote, but that won't help because all I have is the
TypeInfo of the Container!(T). I don't have an instance of a Container!(T).
But I think I found a way to do what i want in the other post.
--bb
More information about the Digitalmars-d-learn
mailing list