On Thursday, 30 December 2021 at 02:04:30 UTC, Ali Çehreli wrote:
On 12/29/21 5:14 PM, Paul Backus wrote:
Therefore, when you write your own copy constructors, you
should always use `inout` if possible, so that
compiler-generated copy constructors will be able to copy
instances of your struct that appear as members of other
structs.
Excellent point. I noticed a typo in the documentation:
struct A
{
this(ref return scope inout A rhs) immutable {}
}
That 'immutable' should be 'inout', right?
I think 'immutable' is correct here, since the usage examples
look like this:
A r1;
const(A) r2;
immutable(A) r3;
// All call the same copy constructor because `inout` acts
like a wildcard
immutable(A) a = r1;
immutable(A) b = r2;
immutable(A) c = r3;