Getting the names of all the top-level functions in module

Stefan Koch uplink.coder at googlemail.com
Tue Sep 21 14:47:33 UTC 2021


On Tuesday, 21 September 2021 at 14:20:50 UTC, Adam D Ruppe wrote:
> On Tuesday, 21 September 2021 at 13:29:44 UTC, Stefan Koch

>
>
> This works today:
>
> import arsd.simpledisplay; // or whatever
>
> enum string[] functionNames(alias M) = ()
> {
>         string[] names;
>         foreach(memberName; __traits(derivedMembers, M))
>             static if (is(typeof(__traits(getMember, M, 
> memberName)) ==
>             function))
>                 names ~= memberName;
>         return names;
> }();
>
> pragma(msg, functionNames!(arsd.simpledisplay));
>

This does work. Interesting.

But had I not posted here would I have been able to get to the 
template you posted above?

I am not trying to over-complicate anything this is what I 
naturally arrive at.
After spending more than 20 minutes to get it to show me the 
answer I am looking for.



More information about the Digitalmars-d mailing list