Move Constructor Syntax

ShadoLight ettienne.gilbert at gmail.com
Wed Oct 16 10:39:39 UTC 2024


On Tuesday, 15 October 2024 at 19:29:11 UTC, Arafel wrote:
> On 15/10/24 20:29, Max Samukha wrote:
>> On Tuesday, 15 October 2024 at 17:52:43 UTC, Arafel wrote:
>
...
> ```d
> struct S {
> 	this (int i) { }
> 	this (S s) { }
> }
>
> void main() {
> 	S s1, s2;
> 	s1 = S(1);
> 	s2 = S(s1);
> 	// Is s1 valid here?
> }
> ```

unlike Walter/Timon/Razvan/Manu/<add others> I'm also no language 
design guru but, in the above case:

- s1 is an lvalue, so shouldn't a copy ctor be implicitly 
generated by the compiler (like in C++)..?
- ... and be preferred in this case?

Something like:
```d
	S s1, s2, s3;
	s1 = S(1);       // this (int i)
	s2 = S(s1);      // this (ref S s)  -> implicit
         s3 = S(S(2));    // this (S s)
         // ...and s1 is valid here
```



More information about the Digitalmars-d mailing list