digitalmars.D.learn - How to find all modules in a package?
- Domain (2/2) Aug 02 2022 I want to find out all public functions in all modules in a
- Piotr Mitana (2/4) Aug 03 2022 I think it's not possible.
- Adam D Ruppe (3/5) Aug 03 2022 No, D packages are not closed; anyone can add new modules to them
- frame (10/12) Aug 03 2022 You can do something like that:
- Domain (2/14) Aug 04 2022 This give me all symbols in the package.d file.
- H. S. Teoh (21/39) Aug 04 2022 static foreach (sym; __traits(allMembers, mixin("std.string")))
I want to find out all public functions in all modules in a package. Can I do that at compile time?
Aug 02 2022
On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote:I want to find out all public functions in all modules in a package. Can I do that at compile time?I think it's not possible.
Aug 03 2022
On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote:I want to find out all public functions in all modules in a package. Can I do that at compile time?No, D packages are not closed; anyone can add new modules to them at any time.
Aug 03 2022
On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote:I want to find out all public functions in all modules in a package. Can I do that at compile time?You can do something like that: ```d static foreach (sym; __traits(allMembers, mixin("std.string"))) { pragma(msg, sym.stringof); } ``` Then you would have to check if `sym` is a template or function or something else.
Aug 03 2022
On Wednesday, 3 August 2022 at 12:27:32 UTC, frame wrote:On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote:This give me all symbols in the package.d file.I want to find out all public functions in all modules in a package. Can I do that at compile time?You can do something like that: ```d static foreach (sym; __traits(allMembers, mixin("std.string"))) { pragma(msg, sym.stringof); } ``` Then you would have to check if `sym` is a template or function or something else.
Aug 04 2022
On Thu, Aug 04, 2022 at 07:22:04AM +0000, Domain via Digitalmars-d-learn wrote:On Wednesday, 3 August 2022 at 12:27:32 UTC, frame wrote:static foreach (sym; __traits(allMembers, mixin("std.string"))) { // Note that sym is already a string, there is no need to use .stringof static if (is(typeof(mixin(sym)) == function)) pragma(msg, sym); } Note, however, that this doesn't pick up on template functions, only non-template global functions. You can detect templates with `static if (__traits(isTemplate, mixin(sym)))`, but in general there is no way to know whether it's a template function, because in order to introspect it you have to instantiate it first, but there is no general way to automatically instantiate a template. Its arguments can be subject to arbitrary signature constraints, and it may in theory be a template function only for a subset of its possible arguments, so there isn't any good way to automatically deduce what template arguments would instantiate into a valid function. You can only get at a template function if you already have an instantiation of it. T -- Guns don't kill people. Bullets do.On Wednesday, 3 August 2022 at 03:36:55 UTC, Domain wrote:This give me all symbols in the package.d file.I want to find out all public functions in all modules in a package. Can I do that at compile time?You can do something like that: ```d static foreach (sym; __traits(allMembers, mixin("std.string"))) { pragma(msg, sym.stringof); } ``` Then you would have to check if `sym` is a template or function or something else.
Aug 04 2022