digitalmars.D.learn - Subclass template arguments from a non-templated interface
- Callum Anderson (31/31) Aug 08 2011 I have the following (sort of) situation:
I have the following (sort of) situation: interface Handle { } class A(T...) : Handle { T[0] m_one; T[1] m_two; etc.. T[0] getOne() { return m_one; } } class B { Handle[] m_array; } The reason I want to inherit A from Handle is so I don't have to keep using the variadic template arguments on any class which wants to have a member of type A (T...). In my case there are many possible combinations for the template arguments (T...). The problem is that Handle doesn't know anything about the types of the members of A, so it can't (I think) provide an interface to any functions in A like 'getOne()'. So it can't give me the accessor functions I need to get at A's data (or maybe i'm wrong?). Is there a neat way for a class like A(T...) to enable Handle to cast to its (A! T's) type? Like some way of having Handle call a function in A which returns or somehow gives Handle a typetuple of the template arguments to A? Since Handle can only call functions in A which it defines itself, I don't think this is possible? Or am I just going about this all wrong? I just need some kind of generic handle to objects of type A(T...) which can cast itself to its specific A!T when needed. I know the A(T...)'s are all different types to the compiler, but D seems to have lots of tricks up its sleeve. Many thanks!
Aug 08 2011