Methods for expanding class in another class/struct

k2aj krzysztof.jajesnica at gmail.com
Sat Sep 26 11:30:23 UTC 2020


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();
     }
}


More information about the Digitalmars-d-learn mailing list