Re: Proper way to handle "alias this" deprecation for classes

2023-05-17 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 17 May 2023 at 08:00:17 UTC, Dom DiSc wrote: If you want auto-conversion, you should be more explicit: ```d float opCast() { } ``` because if you return "auto" it is not the highest-prio fit and therefore not chosen. If you have multiple choices, you still don't need to use

Re: Proper way to handle "alias this" deprecation for classes

2023-05-17 Thread Dom DiSc via Digitalmars-d-learn
On Friday, 12 May 2023 at 15:00:48 UTC, Salih Dincer wrote: ```d struct Fraction { int num, den; this(int n, int d) { num = n; den = d; } // Cast Expression : convert float value of fraction auto opCast(T :

Re: Proper way to handle "alias this" deprecation for classes

2023-05-12 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 7 May 2023 at 21:04:05 UTC, Inkrementator wrote: Open question to everybody: What you're opinion on using opCast for this? Since it's a type conversion, it seems fitting to me. Can't converting without explicitly specifying in D is a big shortcoming in my opinion. There is such a

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 10, 2023 at 10:57:13PM +, Chris Piker via Digitalmars-d-learn wrote: > On Wednesday, 10 May 2023 at 20:25:48 UTC, H. S. Teoh wrote: > > On Wed, May 10, 2023 at 07:56:10PM +, Chris Piker via > > Digitalmars-d-learn wrote: [...] > > I also suffer from left/right confusion, and

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread Chris Piker via Digitalmars-d-learn
On Wednesday, 10 May 2023 at 20:25:48 UTC, H. S. Teoh wrote: On Wed, May 10, 2023 at 07:56:10PM +, Chris Piker via Digitalmars-d-learn wrote: [...] I also suffer from left/right confusion, and always have to pause to think about which is the right(!) word before uttering it. Oh, I though

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 10, 2023 at 07:56:10PM +, Chris Piker via Digitalmars-d-learn wrote: [...] > My problem with the terms lvalue and rvalue is much more basic, and is > just a personal one that only affects probably 0.1% of people. I just > can't keep left vs. right straight in real life. "Right"

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread Chris Piker via Digitalmars-d-learn
On Wednesday, 10 May 2023 at 16:01:40 UTC, H. S. Teoh wrote: x = y; ^ ^ | | lvalue rvalue ... // This is OK: x = y + 1; // This is not OK: (y + 1) = x; Thanks for the clear explanation. My problem with the

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 10, 2023 at 03:24:48PM +, Chris Piker via Digitalmars-d-learn wrote: [...] > It's off topic, but I forget why managing memory for rvalues* was > pushed onto the programmer and not handled by the compiler. I'm sure > there is a good reason but it does seem like a symmetry breaking

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread Chris Piker via Digitalmars-d-learn
On Wednesday, 10 May 2023 at 14:42:50 UTC, Inkrementator wrote: On Sunday, 7 May 2023 at 21:12:22 UTC, Chris Piker wrote: https://gist.github.com/run-dlang/9b7aec72710b1108fc8277789776962a Thanks for posting that. Reading over the code I'm reminded that I never cared whether something was

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 7 May 2023 at 21:12:22 UTC, Chris Piker wrote: On the other hand, your first suggestion of using opCast() does seem like a reasonable choice to me. Can you provide a short code snippet using opCast to achieve the same result? I've never used it, and particularly I know that I

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Ali Çehreli via Digitalmars-d-learn
On 5/7/23 13:44, Chris Piker wrote: > to fix the problem I > just delete the alias this line from dpq2, see what unit tests and app > code it breaks, then fix each of those. Yes but I neglected the lvalue/rvalue issue. In some cases the code won't compile if the return type of the newly

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Chris Piker via Digitalmars-d-learn
On Sunday, 7 May 2023 at 21:04:05 UTC, Inkrementator wrote: On Sunday, 7 May 2023 at 18:19:04 UTC, Ali Çehreli wrote: alias this is for implicit type conversions, which can be achieved explicitly as well. Open question to everybody: What you're opinion on using opCast for this? Since it's a

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 7 May 2023 at 18:19:04 UTC, Ali Çehreli wrote: alias this is for implicit type conversions, which can be achieved explicitly as well. Open question to everybody: What you're opinion on using opCast for this? Since it's a type conversion, it seems fitting to me. And another

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Chris Piker via Digitalmars-d-learn
On Sunday, 7 May 2023 at 18:19:04 UTC, Ali Çehreli wrote: auto main() { auto c = new C(); // The same type conversion is now explicit: foo(c.asIntPtr); } Hi Ali Ah, very clear explanation, thanks! So basically to fix the problem I just delete the alias this line from dpq2, see

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Ali Çehreli via Digitalmars-d-learn
On 5/7/23 10:55, Chris Piker wrote: > According to dmd 2.103, alias this is > deprecated for classes, so I'd like to correct the problem. alias this is for implicit type conversions, which can be achieved explicitly as well. Given the following old code: class C { int* result; alias

Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Chris Piker via Digitalmars-d-learn
Hi D One of the dependencies for my project has a class that makes use of the `alias x this` construct. According to dmd 2.103, alias this is deprecated for classes, so I'd like to correct the problem. Is there a specific paragraph or two that I can read to find out what is the