DIP 1018--The Copy Constructor--Community Review Round 1

Kagamin spam at here.lot
Thu Dec 20 14:41:49 UTC 2018

On Wednesday, 19 December 2018 at 13:40:41 UTC, RazvanN wrote:
> All this copies become useless when using the copy constructor.

A copy constructor is very verbose though, imagine a copy 
constructor for a struct with 30 fields, where it copies 29 
fields and sets the 30th to null. Postblit is observation of 
pattern that copy constructor usually changes only a small part 
of the struct. In this synthetic example copying wouldn't make 
much difference:
for this code:
struct A
     int b;
     void inc()
         const int shadow_b=b;
         const int t=shadow_b;

A f(ref A a)
     A b=a;
     return b;
`ldc -Os` generates this code for function f:
	movl	(%rdi), %eax
	addl	$1, %eax

More information about the Digitalmars-d mailing list