Get class type parameters at compile time

js.mdnq js_adddot+mdng at gmail.com
Sun Dec 16 17:00:38 PST 2012


I see now why it was returning a bool as that is the type of the 
template argument passed.

class A(bool x = true)

then your TemplateArgs returns `tuple(bool)`. What I'm looking 
for is something that returns `(x)`. For class A(T1, T2, bool x = 
true) I would like `(T1, T2, x)`.

To see why this will help, in my Nested structs code, I have to 
do the following:

class _A(...., bool _NestedLevel = true) {
enum string __ClassNameFix = "_A!(....";
...}

Using what you said about typeof(this), I can now remove the 
class name dependency, so I have this:

enum string __ClassNameFix = __traits(identifier, 
typeof(this))~"!(....";

Now I want to remove the type argument list dependency(the 
`!(...` part).

Once that is done, I can completely remove the __ClassNameFix 
since I can get the class name and template arg names without 
user intervention. The whole point of __ClassNameFix was to 
provide a way for the user to specify the class name and args. I 
had to use strings so I could parse them. (since in my mixins 
I'll set _NestedLevel to false and such, using strings, which is 
easy)

If I could go the next step and get the template argument names 
it will drastically reduce the code in my template mixins.


More information about the Digitalmars-d-learn mailing list