Bug 13771 – any language support capture acquire type?

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-11-24T15:17:05Z
Last change time
2022-12-16T14:23:27Z
Assigned to
No Owner
Creator
galaxylang

Comments

Comment #0 by galaxylang — 2014-11-24T15:17:05Z
auto add(T)(T a,T b) { return to!RetureType(a+b); } void fun(T)(T x) { } fun!double(add(1,2)); fun!int(add(1,2)); just add a implicit RetureType,not need visible,background syntax tree like this auto add(RetureType,T)(T a,T b) but we can see ,the type reduce logical changed from down-up to up-down template SelectFrom(T) { alias SelectFrom=T; } auto add(T=SelectFrom!(ReturnType))(T a,T b) these will change the language' template more magic when mix use with opCast,opDispacth...act
Comment #1 by razvan.nitu1305 — 2022-12-16T14:23:27Z
No, D does not support such features because the return type is always deduced from the function body, not from the surrounding context (there are some exceptions with regards to lambda functions). This is a major change that does really bring too much benefit.