Bug 16023 – Add template or trait to find the importable symbol name for a type

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2016-05-13T20:56:31Z
Last change time
2024-12-01T16:26:48Z
Assigned to
No Owner
Creator
erikas.aubade
Moved to GitHub: phobos#10176 →

Comments

Comment #0 by erikas.aubade — 2016-05-13T20:56:31Z
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.
Comment #1 by robert.schadek — 2024-12-01T16:26:48Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10176 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB