DIP 1018--The Copy Constructor--Final Review

Olivier FAURE couteaubleu at gmail.com
Fri Mar 1 13:59:41 UTC 2019


On Thursday, 28 February 2019 at 10:44:36 UTC, Mike Parker wrote:
> Thanks in advance for your participation.

So, the big point of contention seems to be the possibility that 
structs have copy constructors taking non-const arguments.

I'll note that the language could allow only const arguments for 
copy constructor at first, and allow non-const arguments later 
(whereas the opposite order would be a breaking change).

Also, to the people on this forum who don't like non-const copy 
constructors, how do you propose to deal with this case?

     struct RefCounted(T) {
         int* refcount;
         T* payload;

         /* ... */
     }

     RefCounted p1(10);
     RefCounted p2 = p1;

One possibility would be to introduce a new "head_const" type 
qualifier, that would be used for cases like that. But honestly, 
I'm not sure

     this(ref head_const(RefCounted) other);

would bring much to the table compared to

     this(ref RefCounted other);

especially since then you have to consider introducing 
head_immutable and how they interact with scope and inout, etc.


More information about the Digitalmars-d mailing list