[Issue 12223] New: __traits(getMember,...) needed for aliases
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Feb 21 22:21:33 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12223
Summary: __traits(getMember,...) needed for aliases
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: thecybershadow at gmail.com
--- Comment #0 from Vladimir Panteleev <thecybershadow at gmail.com> 2014-02-22 08:21:27 EET ---
Currently, "x.y" does two things:
1. Looks up "y" in the symbol scope of "x"
2. Interprets "y" with its "this" set to "x"
Sometimes, it is useful to separate these two things.
One can already do 1 without 2 using alias:
alias y = x.y;
However, there is no way to do 2 without 1.
The closest thing we have is __traits(getMember, x, y) - however, it requires
that y is a string, and does not work if it is an alias.
Example:
////////////////////////////////// test.d //////////////////////////////////
static template T(alias v)
{
void set() { v = 42; }
}
struct S
{
int i;
alias t = T!i;
}
void main()
{
alias f = S.t.set;
// ...
S s;
// Goal: call f() with "this" set to s, like this:
s.t.set();
// ... (but without referring to "t" or "set" directly)
//s.f(); // NG
//with (s) f(); // NG
//struct W { S s; alias s this; alias wf = f; }
//W w = W(s); w.wf(); // NG (Issue 12222)
//__traits(getMember, s, f)(); // NG
//__traits(getMember,
// __traits(getMember, s, __traits(identifier, __traits(parent, f))),
// __traits(identifier, f))(); // NG
}
////////////////////////////////////////////////////////////////////////////
I propose adding a __traits(child, x, y), since it will be the reverse
operation of __traits(parent, y).
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list