Re: Operator "+=" overloading for class?

2023-12-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote: auto opOpAssign(string op)(in ElementType rhs) { mixin("return this" ~ op ~ "rhs;"); } ``` check what `op` is. pretty sure it is "+" not "+=" so your element isnt' saved anywhere. also a bit iffy there isn't a member here to

Re: Operator "+=" overloading for class?

2023-12-16 Thread Ki Rill via Digitalmars-d-learn
On Sunday, 17 December 2023 at 04:15:02 UTC, Ki Rill wrote: On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote: I am trying to overload `opOpAssign` for my class. The code [...] I forgot to mention, it is relevant to

Re: Operator "+=" overloading for class?

2023-12-16 Thread Ki Rill via Digitalmars-d-learn
On Sunday, 17 December 2023 at 04:13:20 UTC, Ki Rill wrote: I am trying to overload `opOpAssign` for my class. The code [...] I forgot to mention, it is relevant to [`Value`](https://github.com/rillki/tiny-grad/blob/main/source/rk/tgrad/core/value.d) class only.

Operator "+=" overloading for class?

2023-12-16 Thread Ki Rill via Digitalmars-d-learn
I am trying to overload `opOpAssign` for my class. The code compiles, but it does not seem to be working. ```d // binary operations have already been implemented for Value // i need +=, -=, *=, /= auto opOpAssign(string op)(Value rhs) { mixin("return this" ~ op ~ "rhs;"); } auto

Re: Changing behavior of associative array

2023-12-16 Thread Julian Fondren via Digitalmars-d-learn
On Sunday, 17 December 2023 at 00:10:56 UTC, Kevin Bailey wrote: instead it seems like 'm' is a pointer to a std::map, that is initialized on use if null. (I think it's that latter part that gives the illusion of being already initialized.) Yes:

Re: Changing behavior of associative array

2023-12-16 Thread Kevin Bailey via Digitalmars-d-learn
On Saturday, 16 December 2023 at 22:44:16 UTC, Dennis wrote: That's because `m[f] = 1` initializes the associative array to something non-null. If you pass a `null` AA to a function which adds things, the caller will still have a null pointers. You can initialize a non-null empty AA like

Re: Changing behavior of associative array

2023-12-16 Thread Julian Fondren via Digitalmars-d-learn
On Saturday, 16 December 2023 at 22:44:16 UTC, Dennis wrote: That's because `m[f] = 1` initializes the associative array to something non-null. If you pass a `null` AA to a function which adds things, the caller will still have a null pointers. I've gotten this error in deployed Perl.

Re: Changing behavior of associative array

2023-12-16 Thread Dennis via Digitalmars-d-learn
On Saturday, 16 December 2023 at 21:30:55 UTC, kdevel wrote: If you comment out this line ``` //m[f] = 1; ``` in your main function of your posted code you can catch up with your real programm insofar as you now need a ref parameter here, too. That's because `m[f] = 1` initializes the

Re: now I need -allinst when dmd compiles the unittest

2023-12-16 Thread kdevel via Digitalmars-d-learn
On Tuesday, 5 December 2023 at 03:36:04 UTC, Steven Schveighoffer wrote: Are you using -checkaction=context? Right. [...] For reference: https://issues.dlang.org/show_bug.cgi?id=22374 https://issues.dlang.org/show_bug.cgi?id=22902 https://issues.dlang.org/show_bug.cgi?id=19937 You even

Re: Changing behavior of associative array

2023-12-16 Thread kdevel via Digitalmars-d-learn
On Saturday, 16 December 2023 at 20:04:54 UTC, Kevin Bailey wrote: I've added a TON of writeln's to confirm this. The *instant* I made the parameter "ref", the real program starts acting as expected, and the print-outs show the correct results. If you comment out this line ``` //m[f] =

Changing behavior of associative array

2023-12-16 Thread Kevin Bailey via Digitalmars-d-learn
Perhaps someone can help solve this mystery. I have a sample program that adds structs to an associative array (as keys) in a subroutine. The program passes the array by reference as expected (below). My real program does the same thing and yet the associative array is passed by value. Thus