digitalmars.D.bugs - [Issue 11150] New: Allow aliasing of an aggregate template instance
- d-bugmail puremagic.com (52/52) Sep 30 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11150
- d-bugmail puremagic.com (25/26) Oct 01 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11150
- d-bugmail puremagic.com (10/14) Oct 01 2013 http://d.puremagic.com/issues/show_bug.cgi?id=11150
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 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
http://d.puremagic.com/issues/show_bug.cgi?id=11150 monarchdodra gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |monarchdodra gmail.comCurrently 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
http://d.puremagic.com/issues/show_bug.cgi?id=11150 04:06:44 PDT ---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: -------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?
Oct 01 2013