Going from TypeInfo of template to TypeInfo of template parameter/member
Kirk McDonald
kirklin.mcdonald at gmail.com
Mon Nov 12 17:10:10 PST 2007
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
Not in the general case. However, you can easily add something like this:
struct Container(T) {
alias T value_type;
T[] elems;
}
Thus, Container!(float).value_type will be float.
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d-learn
mailing list