www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12223] New: __traits(getMember,...) needed for aliases

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: thecybershadow gmail.com



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: -------
Feb 21 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12223


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



00:49:49 PST ---
That's a rather complicated example. Is the following what you're after?

-----
struct S
{
    void foo() { }
}

void main()
{
    alias f = S.foo;

    S s;

    __traits(getChild, s, f)();  // same as s.foo()
}
-----

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 22 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12223




10:51:10 EET ---
Yes, but it should also work with the original example (if the child is an
alias of a symbol that is not actually declared in the parent, but the "this"
pointer of which is nevertheless of the type of the parent).

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 22 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12223


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



21:57:25 EET ---
https://github.com/D-Programming-Language/dmd/pull/3329

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 22 2014