[Issue 17934] [scope] scopeness entrypoint for unique/ref-counted missing

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 29 14:07:10 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=17934

Paul Backus <snarwin+bugzilla at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |snarwin+bugzilla at gmail.com

--- Comment #11 from Paul Backus <snarwin+bugzilla at gmail.com> ---
One workaround for this is to pass the value to a callback as a scope
parameter, rather than returning it:

---
void withList(alias callback)()
{
    scope l = (() @trusted => List(malloc(1)))();
    callback(l);
}

void test() @safe
{
    Elem elem;
    withList!((scope ref l) {
        elem = l.front; // scope variable `l` assigned to `elem` with longer
lifetime
    });
}
---

--


More information about the Digitalmars-d-bugs mailing list