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