Copy Constructor

Paul Backus snarwin at gmail.com
Sun Jun 5 18:57:16 UTC 2022


On Sunday, 5 June 2022 at 18:50:13 UTC, Salih Dincer wrote:
> On Sunday, 5 June 2022 at 15:45:17 UTC, Salih Dincer wrote:
>> Hi,
>>
>> Let be the structure Foo that wraps an int pointer. Let's 
>> setup Foo in 3 different ways:
>>> 1. Foo one = Foo(1);
>>> 2. Foo two = 2;
>>> 3. [ Foo(3) ];
>
> There is a fourth possibility:
> ```d
> int[] arr = [ one, two, Foo(3), *(new Foo(4)) ];
> ```
> The 1st, 2nd and 4th elements of array are copied, but the 3rd 
> element is not. Could it have something to do with CTFE?
> https://tour.dlang.org/tour/en/gems/compile-time-function-evaluation-ctfe

Since the 3rd element is an rvalue, it is moved into the array 
rather than copied.


More information about the Digitalmars-d-learn mailing list