Bug 8075 – Optional parameters should be able to refer to previous parameters

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-09T18:11:13Z
Last change time
2024-12-13T17:59:55Z
Assigned to
No Owner
Creator
dlang+issues
Moved to GitHub: dmd#18439 →

Comments

Comment #0 by dlang+issues — 2012-05-09T18:11:13Z
void process(R)(R items, size_t maxCount = items.length) { } unittest { process([1, 2, 3]); } It would be great if this worked.
Comment #1 by schveiguy — 2012-05-10T04:58:18Z
I really like this idea. But there must be a provision that the expression isn't substituted wholesale. For instance, your example should not expand to: process([1, 2, 3], [1, 2, 3].length); which allocates *twice*, the second time just to get the length. It should really expand to this: auto items = [1, 2, 3]; process(items, items.length);
Comment #2 by dlang+issues — 2012-05-10T15:12:23Z
Also, not sure if this is a related or a separate issue, but we should also be able to refer to "this" object inside the optional arguments...
Comment #3 by robert.schadek — 2024-12-13T17:59:55Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18439 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB