digitalmars.D.learn - D RAII with postblit disabled
- Norm (24/24) Mar 26 2018 Hi All,
- Adam D. Ruppe (4/5) Mar 26 2018 I'd also add `@disable this();` and then a `static O make() {
- Norm (2/7) Mar 26 2018 Perfect, thanks.
- Norm (17/22) Mar 28 2018 OK, that got me over the first hurdle but I still cannot use RAII
- Adam D. Ruppe (3/6) Mar 28 2018 You'll have to do it all the way up (unless you can use a
- Norm (2/8) Mar 28 2018 OK, thanks.
Hi All, What's the best way to do this in D? E.g. --- struct O { int* value; disable this(this); /+ this() { this.value = theAllocator.make!int(99); } +/ ~this() { theAllocator.dispose(this.value); } } O obj = O(); // Ideally this would be allocated but it simply run O.init --- Thanks Norm
Mar 26 2018
On Tuesday, 27 March 2018 at 02:35:23 UTC, Norm wrote:What's the best way to do this in D?I'd also add ` disable this();` and then a `static O make() { return O(theAllocator.make!int(99)); }` than you construct it with that static make function.
Mar 26 2018
On Tuesday, 27 March 2018 at 02:43:15 UTC, Adam D. Ruppe wrote:On Tuesday, 27 March 2018 at 02:35:23 UTC, Norm wrote:Perfect, thanks.What's the best way to do this in D?I'd also add ` disable this();` and then a `static O make() { return O(theAllocator.make!int(99)); }` than you construct it with that static make function.
Mar 26 2018
On Tuesday, 27 March 2018 at 02:43:15 UTC, Adam D. Ruppe wrote:On Tuesday, 27 March 2018 at 02:35:23 UTC, Norm wrote:OK, that got me over the first hurdle but I still cannot use RAII with struct member vars. E.g. --- struct Resource { this() {allocate_something();} ~this() {release_something();} } struct S { Resource resource; } --- Is there a way to do this in D, or does it require special "create" functions for every struct that has a RAII-like struct as a member? Thanks, NormWhat's the best way to do this in D?I'd also add ` disable this();` and then a `static O make() { return O(theAllocator.make!int(99)); }` than you construct it with that static make function.
Mar 28 2018
On Thursday, 29 March 2018 at 04:12:38 UTC, Norm wrote:Is there a way to do this in D, or does it require special "create" functions for every struct that has a RAII-like struct as a member?You'll have to do it all the way up (unless you can use a constructor with an argument and call that instead)
Mar 28 2018
On Thursday, 29 March 2018 at 04:16:55 UTC, Adam D. Ruppe wrote:On Thursday, 29 March 2018 at 04:12:38 UTC, Norm wrote:OK, thanks.Is there a way to do this in D, or does it require special "create" functions for every struct that has a RAII-like struct as a member?You'll have to do it all the way up (unless you can use a constructor with an argument and call that instead)
Mar 28 2018