Currently, I (with the help of #D on irc.freenode.net) couldn't find any way to define a function or delegate literal returning a reference.
our best guess at the syntax was
delegate ref T (params) { body }
or, to be more general,
delegate ATTRIBUTE T (params) { body }
example:
void main() {
auto bar = new int[5];
auto foo = delegate ref int(size_t i) { return bar[i]; };
}
This example fails with the error "basic type expected, not ref".
Note: even if this did work, assigning functions returning ref does not work properly, so this bug depends on #8064.
Comment #1 by b2.temp — 2017-03-09T21:48:18Z
Changed to enhancement. This is not even something that exist in the grammar, which would have to be changed to something like
delegate Typeopt refopt ParameterMemberAttributes opt FunctionLiteralBody
Comment #2 by dlang-bot — 2019-04-05T20:06:18Z
@BorisCarvajal updated dlang/dmd pull request #9558 "Fixes issues 16271, 18825, 8065, 5050 - Allow function literals return by reference" fixing this issue:
- Fixes issues 16271, 18825, 8065, 5050 - Allow function literals return by reference
https://github.com/dlang/dmd/pull/9558
Comment #3 by dlang-bot — 2019-04-07T16:18:46Z
dlang/dmd pull request #9558 "Fixes issues 16271, 18825, 8065, 5050 - Allow function literals return by reference" was merged into master:
- 60251b8f0e191a8f0f5142ddd2d3807d0e06c58a by Boris Carvajal:
Fixes issues 16271, 18825, 8065, 5050 - Allow function literals return by reference
https://github.com/dlang/dmd/pull/9558