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 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: How to do "C++ classes"?

2021-09-20 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 20 September 2021 at 15:56:44 UTC, Ferhat Kurtulmuş wrote: On Monday, 20 September 2021 at 15:45:08 UTC, Adam D Ruppe wrote: On Monday, 20 September 2021 at 15:35:02 UTC, Ferhat Kurtulmuş wrote: I thought it's stack-allocated and scoped. It is. But when I try to return a class

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

Re: How to do "C++ classes"?

2021-09-20 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Saturday, 18 September 2021 at 22:16:32 UTC, Adam D Ruppe wrote: On Saturday, 18 September 2021 at 15:38:38 UTC, rempas wrote: I'm seeing in the page about "BeterC" and in the part about the [retained features](https://dlang.org/spec/betterc.html#retained), the #11 says about "COM classes

Re: How to do "C++ classes"?

2021-09-20 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 20 September 2021 at 15:35:02 UTC, Ferhat Kurtulmuş wrote: I thought it's stack-allocated and scoped. It is. But when I try to return a class instance from a function, it still works? dmd only makes that an error if you specify `@safe` and i think `-dip1000`. Try adding one or

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

zsh: command not found: rdmd

2021-09-20 Thread leikang via Digitalmars-d-learn
Enter dmd lk01.d in vscode, the terminal displays zsh: command not found: dmd, an error is reported, I don't know what the problem is, can it only be run in /Users/mac1094/dmd2/osx/bin?

Cannot Instantiate SumType

2021-09-20 Thread surlymoor via Digitalmars-d-learn
I'm experiencing an error when instantiating `SumType` with an aggregate template that itself is instantiated with a void function. In other words... ```d struct Foo(alias f) {} // As the error implies, altering it to be non-void makes everything copacetic~ void bar() {} alias S =

Re: Program crash: GC destroys an object unexpectedly

2021-09-20 Thread eugene via Digitalmars-d-learn
On Sunday, 19 September 2021 at 21:10:16 UTC, eugene wrote: I rearranged the code of main() like this: Similar rearrangement fixed the echo-client as well. (I moved creation of Stopper to the very beginning of main())

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: Cannot Instantiate SumType

2021-09-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 September 2021 at 11:21:28 UTC, surlymoor wrote: The error in question... ``` Error: variable `std.typecons.ReplaceTypeUnless!(isSumTypeInstance, This, SumType!(Foo!(bar)), Foo!(bar)).F!(bar).replaceTemplateArgs` type `void` is inferred from initializer `bar()`, and variables

Re: How to do "C++ classes"?

2021-09-20 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Monday, 20 September 2021 at 15:45:08 UTC, Adam D Ruppe wrote: On Monday, 20 September 2021 at 15:35:02 UTC, Ferhat Kurtulmuş wrote: I thought it's stack-allocated and scoped. It is. But when I try to return a class instance from a function, it still works? dmd only makes that an error

type in extern declaration

2021-09-20 Thread NonNull via Digitalmars-d-learn
How do I write the type of a function so as to alias it, and use that in an extern(C) declaration? For example, how do I write the type of an external function int main2(int argc, char** argv) { // } ? This is not int function(int, char**) because this is the type of a function pointer

Re: type in extern declaration

2021-09-20 Thread Paul Backus via Digitalmars-d-learn
On Monday, 20 September 2021 at 20:02:24 UTC, NonNull wrote: How do I write the type of a function so as to alias it, and use that in an extern(C) declaration? For example, how do I write the type of an external function int main2(int argc, char** argv) { // } You can create an alias to

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

Scope with owner types

2021-09-20 Thread Thomas Gregory via Digitalmars-d-learn
I have made an owner type that wraps malloc'd pointers with custom destroy functions from a C library and utilizes `RefCounted` for safety. I would like to be able to use the owner type `Memory` implicitly as its underlying pointer type via `alias this`. ``` struct Memory(T, alias destroy)

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 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: zsh: command not found: rdmd

2021-09-20 Thread russhy via Digitalmars-d-learn
On Monday, 20 September 2021 at 11:04:42 UTC, leikang wrote: Enter dmd lk01.d in vscode, the terminal displays zsh: command not found: dmd, an error is reported, I don't know what the problem is, can it only be run in /Users/mac1094/dmd2/osx/bin? How have you installed dmd?

Re: Templates for instantiating derived class

2021-09-20 Thread Adam Ruppe via Digitalmars-d-learn
On Monday, 20 September 2021 at 22:16:47 UTC, rjkilpatrick wrote: auto opBinary(string op)(int rhs) const if (op == "+") { return new Super(_a + rhs); // Creates of type Super even when called from derived class } Make this auto opBinary(string op, this This)(int rhs)

Re: zsh: command not found: rdmd

2021-09-20 Thread leikang via Digitalmars-d-learn
On Monday, 20 September 2021 at 21:51:32 UTC, russhy wrote: On Monday, 20 September 2021 at 11:04:42 UTC, leikang wrote: Enter dmd lk01.d in vscode, the terminal displays zsh: command not found: dmd, an error is reported, I don't know what the problem is, can it only be run in

Re: Cannot Instantiate SumType

2021-09-20 Thread surlymoor via Digitalmars-d-learn
On Monday, 20 September 2021 at 15:33:23 UTC, Paul Backus wrote: On Monday, 20 September 2021 at 11:21:28 UTC, surlymoor wrote: The error in question... ``` Error: variable `std.typecons.ReplaceTypeUnless!(isSumTypeInstance, This, SumType!(Foo!(bar)), Foo!(bar)).F!(bar).replaceTemplateArgs`

How to make clang use a different tk framework version on MacOS?

2021-09-20 Thread tastyminerals via Digitalmars-d-learn
My tkd GUI app started getting compiled with an outdated 8.5 Tk framework version which gets shipped with command line tools: `xcode-select --install`. As a result, the UI doesn't display icons and is laggy. When you run the compiled tk app, you get a notorious warning: ``` DEPRECATION

Re: Templates for instantiating derived class

2021-09-20 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/20/21 6:16 PM, rjkilpatrick wrote: Essentially, I would like to write a template that calls the constructor of the parent class or the constructor of the inherited class, depending on its type. ... Some kind of `return new this(...)` would be good, but that's not possible. I think it

Re: zsh: command not found: rdmd

2021-09-20 Thread tastyminerals via Digitalmars-d-learn
On Monday, 20 September 2021 at 11:04:42 UTC, leikang wrote: Enter dmd lk01.d in vscode, the terminal displays zsh: command not found: dmd, an error is reported, I don't know what the problem is, can it only be run in /Users/mac1094/dmd2/osx/bin? Keep in mind that if you have M1 machine, you

Templates for instantiating derived class

2021-09-20 Thread rjkilpatrick via Digitalmars-d-learn
Essentially, I would like to write a template that calls the constructor of the parent class or the constructor of the inherited class, depending on its type. ```d #!/usr/bin/env dub /+ dub.sdl: name "mwe" +/ class Super { private int _a; this(){} this(int a) { _a =

Re: type in extern declaration

2021-09-20 Thread Tejas via Digitalmars-d-learn
On Monday, 20 September 2021 at 20:02:24 UTC, NonNull wrote: How do I write the type of a function so as to alias it, and use that in an extern(C) declaration? For example, how do I write the type of an external function int main2(int argc, char** argv) { // } ? This is not int

Re: zsh: command not found: rdmd

2021-09-20 Thread Tejas via Digitalmars-d-learn
On Tuesday, 21 September 2021 at 01:02:30 UTC, leikang wrote: On Monday, 20 September 2021 at 21:51:32 UTC, russhy wrote: On Monday, 20 September 2021 at 11:04:42 UTC, leikang wrote: Enter dmd lk01.d in vscode, the terminal displays zsh: command not found: dmd, an error is reported, I don't