[Issue 11150] New: Allow aliasing of an aggregate template instance
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Sep 30 15:26:36 PDT 2013
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 at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at 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: -------
More information about the Digitalmars-d-bugs
mailing list