digitalmars.D.learn - __traits with alias
- sigod (14/14) May 07 2014 void registerAll(alias module_)()
- Philippe Sigaud via Digitalmars-d-learn (18/22) May 08 2014 It's a syntax limitation for alias. That bites us from time to time.
- sigod (4/11) May 08 2014 Oh, thank you.
void registerAll(alias module_)() { foreach (m; __traits(derivedMembers, module_)) { regInner!(__traits(getMember, module_, m)); // compiles alias a = __traits(getMember, module_, m); // fails //Error: basic type expected, not __traits //Error: semicolon expected to close alias declaration } } void regInner(alias T)() { // ... } Is this a bug or I've missed something?
May 07 2014
alias a = __traits(getMember, module_, m); // fails //Error: basic type expected, not __traits //Error: semicolon expected to close alias declarationIs this a bug or I've missed something?It's a syntax limitation for alias. That bites us from time to time. A workaround is to wrap it into another template, to 'hide' __traits. Like this: alias Alias(alias a) = a; // A bit circular, I know. void registerAll(alias module_)() { foreach (m; __traits(derivedMembers, module_)) { regInner!(__traits(getMember, module_, m)); alias a = Alias!(__traits(getMember, module_, m)); // compiles } } void regInner(alias T)() { // ... } void main(){} I think there is bug report / enhancement for this. I find it a bit annoying, since aliasing a __traits expression is quite common.
May 08 2014
On Thursday, 8 May 2014 at 07:33:34 UTC, Philippe Sigaud via Digitalmars-d-learn wrote:A workaround is to wrap it into another template, to 'hide' __traits. Like this: alias Alias(alias a) = a; // A bit circular, I know.Oh, thank you.I think there is bug report / enhancement for this. I find it a bit annoying, since aliasing a __traits expression is quite common.This one https://issues.dlang.org/show_bug.cgi?id=7804, I believe.
May 08 2014