Bug 11150 – Symbol alias of member function impossible to be called

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-30T15:26:34Z
Last change time
2022-07-04T16:58:46Z
Assigned to
No Owner
Creator
Andrej Mitrovic

Comments

Comment #0 by andrej.mitrovich — 2013-09-30T15:26:34Z
----- 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.
Comment #1 by monarchdodra — 2013-10-01T00:33:59Z
(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.
Comment #2 by andrej.mitrovich — 2013-10-01T04:06:44Z
(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.
Comment #3 by andrej.mitrovich — 2022-07-04T16:58:46Z
This is an invalid issue. Understanding how member function calls work makes this clear.