Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-21 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/21/21 2:06 AM, Tejas wrote: On Monday, 20 September 2021 at 18:13:53 UTC, Steven Schveighoffer wrote: On 9/20/21 10:22 AM, Tejas wrote: In case you still want to delete stuff deterministically despite what Steve said, I suggest you make your `struct` a reference and use

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-21 Thread Tejas via Digitalmars-d-learn
On Monday, 20 September 2021 at 18:13:53 UTC, Steven Schveighoffer wrote: On 9/20/21 10:22 AM, Tejas wrote: In case you still want to delete stuff deterministically despite what Steve said, I suggest you make your `struct` a reference and use `core.memory.__delete`(not recommended to use this

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/20/21 10:22 AM, Tejas wrote: In case you still want to delete stuff deterministically despite what Steve said, I suggest you make your `struct` a reference and use `core.memory.__delete`(not recommended to use this carelessly, btw) Do not call `__delete` here, use `destroy`. `__delete`

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Ali Çehreli via Digitalmars-d-learn
On 9/20/21 5:23 AM, Learner wrote: I was expecting S instance dtor called S is being destructed If you are sure the element can be destroyed, you can call destroy(): import std.stdio; enum someSpecialInitValue = 777; struct S { int i = someSpecialInitValue; this(int i) { this.i

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 September 2021 at 14:03:09 UTC, Tejas wrote: On Monday, 20 September 2021 at 13:48:01 UTC, Tejas wrote: On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: [...] I think it *is* being called: ```d import std.stdio; struct S { int a; this(int param){

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 September 2021 at 13:48:01 UTC, Tejas wrote: On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: [...] I think it *is* being called: ```d import std.stdio; struct S { int a; this(int param){ a = param; } ~this() {

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/20/21 8:23 AM, Learner wrote: I was expecting something like going out of scope for that ```d import std.stdio; struct S {     ~this()     {     writeln("S is being destructed");     } } void main() { S[int] aa;     aa[1] = S();     aa.remove(1);     writeln("Why no dtor

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread jfondren via Digitalmars-d-learn
On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: I was expecting something like going out of scope for that ```(D) import std.stdio; struct S { ~this() { writeln("S is being destructed"); } } void main() { S[int] aa; aa[1] = S(); aa.remove(1);

Re: Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 September 2021 at 12:23:00 UTC, Learner wrote: I was expecting something like going out of scope for that ```(D) import std.stdio; struct S { ~this() { writeln("S is being destructed"); } } void main() { S[int] aa; aa[1] = S(); aa.remove(1);

Why dtor are not executed when removing a struct from associative arrays?

2021-09-20 Thread Learner via Digitalmars-d-learn
I was expecting something like going out of scope for that ```(D) import std.stdio; struct S { ~this() { writeln("S is being destructed"); } } void main() { S[int] aa; aa[1] = S(); aa.remove(1); writeln("Why no dtor call on remove?"); } I was expecting