Anybody have any idea on how to do shared operator overloads?

Ruby The Roobster rubytheroobster at yandex.com
Thu Jun 2 01:49:32 UTC 2022


On Thursday, 2 June 2022 at 01:29:39 UTC, Ruby The Roobster wrote:
> On Thursday, 2 June 2022 at 01:00:57 UTC, Ali Çehreli wrote:
>> On 6/1/22 17:36, Ruby The Roobster wrote:
>> > A stripped down version of some code I have:
>>
>> Not much experience here but I made two changes:
>>
>> 1) Added 'shared':
>>
>> >          this(Complex!real num = Complex!real(0,0)) shared
>> >          {
>> >              this.num = num;
>> >          }
>> >          this(shared Complex!real num = cast(shared
>> > Complex!real)Complex!real(0,0))
>> >          {
>> >              this.num.re = num.re;
>> >              this.im.re = im.re;
>>
>> 2) Fixed apparent typos:
>>
>>   this.num.im = num.im;
>>
>> >          }
>>
>> I can't guarantee that correct functions are called. It just 
>> compiles with 2.100.0. :)
>>
>> Ali
>
Yes, those were typos.  However, when making this post, I forgot 
to mark ```this(shared Complex!real num = cast(shared 
Complex!real)Complex!real(0,0))``` as shared.  The other 
constructor is not marked as shared in my code, considering as 
shared classes have all of their members marked as shared.

I also have a bug:  __traits(compiles) only checks if the 
expressions are SEMANTICALLY correct, not if they actually 
compile, which they don't.

Interestingly, this code compiles between 2.063 and 2.066.1, if 
you were to put it into run.dlang.io, given the above changes 
(including the p1 + p2!), and set to all compilers.


More information about the Digitalmars-d-learn mailing list