digitalmars.D.learn - Taming templates and mixin magic: type inpector helper in D/Phobos?
- Carlos Navarro (20/20) Apr 03 2018 As a newbie in D (and making a lots of mistakes), I've found
- Uknown (11/31) Apr 04 2018 you might want to check std.traits [0] and __traits [1]. They
As a newbie in D (and making a lots of mistakes), I've found myself relying heavily in the use of a rudimentary type inspector to visualize my templated code instantiations. It's simple and incomplete as hell but good enough to see what happens under the hood quickly. QUESTION: Is there a function like that already in D? //real-life example goodEnoughTypeInspector!Human; goodEnoughTypeInspector!(Database!Human); //compile-time output Inspecting type: Human - public string name - public string address - public bool active Inspecting type: Database!(Human) - private string[] name - private string[] address - private bool[] active - public pure nothrow nogc safe ulong() count - public void insert
Apr 03 2018
On Wednesday, 4 April 2018 at 05:28:57 UTC, Carlos Navarro wrote:As a newbie in D (and making a lots of mistakes), I've found myself relying heavily in the use of a rudimentary type inspector to visualize my templated code instantiations. It's simple and incomplete as hell but good enough to see what happens under the hood quickly. QUESTION: Is there a function like that already in D? //real-life example goodEnoughTypeInspector!Human; goodEnoughTypeInspector!(Database!Human); //compile-time output Inspecting type: Human - public string name - public string address - public bool active Inspecting type: Database!(Human) - private string[] name - private string[] address - private bool[] active - public pure nothrow nogc safe ulong() count - public void insertyou might want to check std.traits [0] and __traits [1]. They both contain functions that may be useful. To get members you could use __traits(allMembers, MyTemplate!SomeType); Just check through the docs for relevant functions. You can then compose the relevant function. I wrote a basic version you can play with [2]. [0]: https://dlang.org/phobos/std_traits.html [1]: https://dlang.org/spec/traits.html [2]: https://run.dlang.io/is/COZ89T
Apr 04 2018