copy constructors need documentation

ag0aep6g anonymous at example.com
Mon Aug 5 12:42:34 UTC 2019


On 05.08.19 14:27, Eduard Staniloiu wrote:
> 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.

An immutable opAssign doesn't seem particularly useful, but it's also 
not unsound by itself.

Or is there a good reason why the following shouldn't work?

----
int x;
struct S
{
     void opAssign(S rhs) immutable { ++x; }
}
void main()
{
     immutable S s;
     s = s;
}
----


More information about the Digitalmars-d mailing list