copy constructors need documentation

Eduard Staniloiu edi33416 at gmail.com
Mon Aug 5 12:27:28 UTC 2019


On Monday, 5 August 2019 at 09:07:17 UTC, RazvanN wrote:
> On Monday, 5 August 2019 at 09:01:39 UTC, Manu wrote:
>> On Mon, Aug 5, 2019 at 12:55 AM RazvanN via Digitalmars-d 
>> <digitalmars-d at puremagic.com> wrote:
>>> [...]
>>
>> I'm so sorry, I completely missed that section of doco. It's 
>> actually
>> quite comprehensive.
>> I don't know why I didn't find it initially when I went 
>> looking.
>> Somehow the organisation didn't get me there.
>
> No worries!
>
>> It's a very tough read though, I had to jump around a lot; 
>> like, I was
>> trying to work out why a qualified constructor works, and 
>> that's
>> detailed in another section (which I still don't understand; 
>> how can I
>> assign to an immutable `this`), but yeah, sorry for the false 
>> alarm!
>
> Long story short: that's basically initialization of an 
> immutable `struct`, therefore it is allowed. What I find weird 
> is that you can define opAssign on `immutable` objects (wtf?!).

I believe that the reason behind it is that you can't modify an 
immutable instance,
so defining `opAssign` for `immutable` types wouldn't be of any 
use.

Probably the same should go for `const`.

The curious case is that you can actually define the operator, 
but you can't call it
https://run.dlang.io/is/RE0g9S

I've never written a qualified `opAssign` based on the reasoning 
above and, imho, it holds water.


More information about the Digitalmars-d mailing list