On Saturday, 26 September 2020 at 10:26:15 UTC, IGotD- wrote:
One thing that struck me looking at the source code of scoped, would scoped work inside a class and not only for stack allocations?

It does work, the problem is that scoped returns a Voldemort type, so you have to use typeof(scoped!SomeClass(someConstructorArgs)) to declare a field. Gets really annoying when doing it with any class that doesn't have a zero-argument constructor, especially in generic code.

class Foo {}

class Bar {
    typeof(scoped!Foo()) foo;
    this() {
        foo = scoped!Foo();
    }
}

Reply via email to