[Issue 9748] Wrong scope of templated nested functions in static foreach
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat Sep 27 04:22:20 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=9748
Mathias LANG <pro.mathias.lang at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pro.mathias.lang at gmail.com
--- Comment #2 from Mathias LANG <pro.mathias.lang at gmail.com> ---
Real world use case where I hit this bug:
import std.typetuple, std.traits;
struct UDAStruct {
string identifier;
}
class MyClass {
@(UDAStruct("p3"), UDAStruct("P2"), UDAStruct("p1"))
void func(int p1, string p2, float p3) {}
}
template CmpIdentifier(UDAStruct uda, string pname) {
pragma(msg, "Instantiated for: "~pname);
enum CmpIdentifier = (uda.identifier == pname);
}
unittest {
alias Func = MyClass.func;
enum ParamNames = ParameterIdentifierTuple!Func;
enum ParamAttr = __traits(getAttributes, Func);
foreach (attr; ParamAttr) {
alias Cmp(string s) = CmpIdentifier!(attr, s);
pragma(msg, "Current attr is: "~attr.identifier);
static assert(anySatisfy!(Cmp, ParamNames));
}
}
void main() {}
Output:
Current attr is: p3
Instantiated for: p1
Instantiated for: p2
Instantiated for: p3
Current attr is: P2
Current attr is: p1
(From: http://forum.dlang.org/thread/ojmpcrxrobjoqfrksjcv@forum.dlang.org )
--
More information about the Digitalmars-d-bugs
mailing list