__traits and determining all overridable functions

Christopher Wright dhasenan at gmail.com
Mon Nov 12 16:54:19 PST 2007


Robert Fraser wrote:
> Christopher Wright Wrote:
> 
>> You can't foreach an array at compile time [...]
> 
> Yes you can, in the context of a function.
> 
> string ct_func(string[] arr)
> {
>    foreach(s; arr)
>    { ... }
> }
> 
> mixin(ct_func(__traits(allMembers, Foo)));

You're right. You can use that to, say, do string manipulations based on 
a string array.

However, you cannot use these strings with pragmas or __traits.

I had tried using foreach on __traits(allMembers) in my code, but since 
I went on to do __traits(getVirtualFunctions) using those strings, dmd 
wasn't happy with me. :`(

That's why I use recursive templates in my code.



More information about the Digitalmars-d mailing list