Passing a module in a template parameter list to __traits(allMembers, module)

Philippe Sigaud philippe.sigaud at gmail.com
Tue Feb 26 18:40:28 PST 2013


>
>> Use an alias:
>>
>> string GetMembers(alias T)() {
>
>
> Excellent. An alias parameter is just what I was looking for. Thanks,
> everyone!

Ben,

I present some ideas on this problem in a template tutorial you can find here:

https://github.com/PhilippeSigaud/D-templates-tutorial

In the pdf, it's section 4.3.4 and 4.3.7, in the markdown file, the
related sections are
https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/D-templates-tutorial.md#allmembers
and
https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/D-templates-tutorial.md#getting-all-members-even-overloaded-ones

And to answer H.S. Teoh's question, from the text:

"What’s the point of inspecting a module? Well, first that was just
for fun and to
see if I could duplicate a module or create a struct with an
equivalent members list (all
forwarding to the module’s own members). But the real deal for me was
when using string
mixins to generate some type. If the user uses the mixin in its own
module, it could create
conflicts with already-existing names. So I searched for a way for a
mixin template to
inspect the module it’s currently being instantiated in. Then, I
wanted to write a template
that, given a class name, would give me the entire hierarchy it’s in
(as the local module
scope would see it, that was enough for me).
Then, while testing std.traits.ParameterTypeTuple, I saw that it gives the
parameter typetuple of one function, even when it’s overloaded. So
inspecting a module is
also a way to get the full list of functions with a particular name
and getting the parameter
typetuple for each of them."


More information about the Digitalmars-d mailing list