www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11150] New: Allow aliasing of an aggregate template instance

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11150

           Summary: Allow aliasing of an aggregate template instance
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-30
15:26:34 PDT ---
-----
struct S
{
    T getData(T)() { return T.init; }
}

alias getInt = S.getData!int;

void main()
{
    auto s = S();
    int x = getInt();    // error: need 'this' (expected error)
    int y = s.getInt();  // error: not callable with S (hmm...)
}
-----

Currently it's not possible to easily create an alias of an aggregate template,
forcing the user to always explicitly instantiate such a template at the call
site.

The workaround is to use a helper UFCS template that forwards to an internal
template:

-----
// workaround
T getData(T)(S s) { return s.getDataImpl!T(); }

struct S
{
    T getDataImpl(T)() { return T.init; }
}

alias getInt = getData!int;

void main()
{
    auto s = S();
    int x = s.getInt();  // ok
    // int y = getInt(); // errors, as it should
}
-----

But it would be much simpler if we could use the alias syntax for this.

Since this might be a big enhancement it could use a forum discussion and maybe
a DIP.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 30 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11150


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com


--- Comment #1 from monarchdodra gmail.com 2013-10-01 00:33:59 PDT ---
(In reply to comment #0)
 Currently it's not possible to easily create an alias of an aggregate template,
I'm not sure this has anything to do with templates? //---- struct S { int getData() { return int.init; } } alias getInt = S.getData; void main() { auto s = S(); int x = getInt(); // error: need 'this' (expected error) int y = s.getInt(); // error: not callable with S (hmm...) } //---- Same result. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 01 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11150



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-10-01
04:06:44 PDT ---
(In reply to comment #1)
 (In reply to comment #0)
 Currently it's not possible to easily create an alias of an aggregate template,
I'm not sure this has anything to do with templates?
Maybe a more generalized term like external member aliasing would be the actual feature. Then template support becomes automatic. If it were allowed then API writers wouldn't have to worry too much about adding convenience member aliases, since the users can do it themselves. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 01 2013