Re: How do I call a context objects destructor or some type of exit() function automatically upon exiting a with {} scope?

2025-04-01 Thread Ali Çehreli via Digitalmars-d-learn
On 4/1/25 10:08 AM, Mike Parker wrote: > ``` > scope ctx = new Context; > ``` > > This will allocate the class instance on the stack so the destructor > will be called when the scope exits. Another option is to call the destructor explicitly through destroy(): import std.stdio; class C { ~t

How do I call a context objects destructor or some type of exit() function automatically upon exiting a with {} scope?

2025-04-01 Thread Daniel via Digitalmars-d-learn
I thought the destructor might automatically be called after with (new Context()) {} but it's not. Is there some sort of entry/exit functions like in Python?

Re: How do I call a context objects destructor or some type of exit() function automatically upon exiting a with {} scope?

2025-04-01 Thread Daniel via Digitalmars-d-learn
On Tuesday, 1 April 2025 at 17:33:02 UTC, Ali Çehreli wrote: On 4/1/25 10:08 AM, Mike Parker wrote: > ``` > scope ctx = new Context; > ``` > > This will allocate the class instance on the stack so the destructor > will be called when the scope exits. Another option is to call the destructor expl

How does D lang handle multithreaded applications and static members of classes?

2025-04-01 Thread Daniel via Digitalmars-d-learn
Say I have a static context stack in my class Context, will each new thread receive their own copy of the static member or do I have to account for multiple threads and do it myself?

Re: How do I call a context objects destructor or some type of exit() function automatically upon exiting a with {} scope?

2025-04-01 Thread Daniel via Digitalmars-d-learn
On Tuesday, 1 April 2025 at 17:08:27 UTC, Mike Parker wrote: On Tuesday, 1 April 2025 at 16:54:50 UTC, Daniel Donnelly, Jr. wrote: [...] You've used `new`, which means it's allocated with the GC. In that case, your destructor is a finalizer and may or may not be called at any point during th

Re: How do I call a context objects destructor or some type of exit() function automatically upon exiting a with {} scope?

2025-04-01 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 1 April 2025 at 16:54:50 UTC, Daniel Donnelly, Jr. wrote: I thought the destructor might automatically be called after with (new Context()) {} but it's not. Is there some sort of entry/exit functions like in Python? You've used `new`, which means it's allocated with the GC. In th

Re: How does one use toString() inside of the class's hash function? Compiler error

2025-04-01 Thread Manfred Nowak via Digitalmars-d-learn
On Tuesday, 1 April 2025 at 09:21:25 UTC, Daniel Donnelly, Jr. wrote: It's a major bottleneck to my coding performance. I don't see a good reason to use a random address or some content of a string for hashing. I'm also amazed that a user might be allowed to change values ​​at will; values

Re: How does one use toString() inside of the class's hash function? Compiler error

2025-04-01 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 1 April 2025 at 09:21:25 UTC, Daniel Donnelly, Jr. wrote: Something like this. I know I could very well hash latex member, but what if the user redefines toString() ? So I would like to call toString(), but DMD compiler bitches: ``` Error: @safe function def.Def.toHash cannot cal