[Issue 16023] New: Add template or trait to find the importable symbol name for a type
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri May 13 13:56:31 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=16023
Issue ID: 16023
Summary: Add template or trait to find the importable symbol
name for a type
Product: D
Version: D2
Hardware: x86
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: erikas.aubade at gmail.com
DMD 2.071's new visibility rules make it so that if you're introspecting a type
from inside a template, you need to locally import the module that it comes
from; best practices would dictate you only import the specific symbol you're
attempting to introspect. Unfortunately, none of the ways I could come up
worked in every case
mixin("import " ~ moduleName!T ~": " ~ T.stringof ~ ";");
fails with templated types, as the instantiation causes the parsing to fail.
Substituting __traits(identifier, T) fails on nested types
Using a selective TemplateOf like so:
static if (__traits(compiles, TemplateOf!T)) {
private alias symb = TemplateOf!T;
} else {
private alias symb = T;
}
enum importableName = __traits(identifier, symb);
fails on non-templated classes that inherit from templated ones.
Basically, the long and short of it is that this seems like it should be a
common enough use case to warrant something to help us do this without having
to do a ton of CTFE string parsing and substitution.
--
More information about the Digitalmars-d-bugs
mailing list