digitalmars.D.announce - What's this? (Was: DMD 1.028 and 2.012 releases)
- Aarti_pl (12/12) Mar 07 2008 Did you notice this example in docs?
- Walter Bright (5/17) Mar 07 2008 It's pseudo-code. There is no <== operator nor .~this() in D. I probably...
- Aarti_pl (8/27) Mar 07 2008 Yes, such a pseudo-code should probably be avoided.
- Bill Baxter (4/30) Mar 07 2008 Ohh that's not real code? That is confusing. Just put the pseudocode
- Steven Schveighoffer (47/59) Mar 07 2008 After reading this new feature, I'm really confused. I like the feature...
- Aarti_pl (7/10) Mar 07 2008 Well, it occurred that this example was just a strange kind of "pseudo
Did you notice this example in docs? (http://www.digitalmars.com/d/2.0/struct.html#AssignOverload) S* opAssign(S s) { S tmp <== *this; // bitcopy *this into tmp *this <== s; // bitcopy s into *this tmp.~this(); // call destructor on tmp return this; } It seems to be something new in D 2.012. Does it work? How? BR Marcin Kuszczak (aarti_pl)
Mar 07 2008
Aarti_pl wrote:Did you notice this example in docs? (http://www.digitalmars.com/d/2.0/struct.html#AssignOverload) S* opAssign(S s) { S tmp <== *this; // bitcopy *this into tmp *this <== s; // bitcopy s into *this tmp.~this(); // call destructor on tmp return this; } It seems to be something new in D 2.012. Does it work? How?It's pseudo-code. There is no <== operator nor .~this() in D. I probably made a mistake in presenting it this way, but I was trying to show what was going on. The comments explain what is happening.
Mar 07 2008
Walter Bright pisze:Aarti_pl wrote:Yes, such a pseudo-code should probably be avoided. I thought that there was silently introduced special copy operator. ... the one that would disambiguate ref copying from object copying for example :-) BR Marcin Kuszczak (aarti_pl)Did you notice this example in docs? (http://www.digitalmars.com/d/2.0/struct.html#AssignOverload) S* opAssign(S s) { S tmp <== *this; // bitcopy *this into tmp *this <== s; // bitcopy s into *this tmp.~this(); // call destructor on tmp return this; } It seems to be something new in D 2.012. Does it work? How?It's pseudo-code. There is no <== operator nor .~this() in D. I probably made a mistake in presenting it this way, but I was trying to show what was going on. The comments explain what is happening.
Mar 07 2008
Aarti_pl wrote:Walter Bright pisze:Ohh that's not real code? That is confusing. Just put the pseudocode into comments then it won't be as misleading. --bbAarti_pl wrote:Yes, such a pseudo-code should probably be avoided. I thought that there was silently introduced special copy operator. ... the one that would disambiguate ref copying from object copying for example :-)Did you notice this example in docs? (http://www.digitalmars.com/d/2.0/struct.html#AssignOverload) S* opAssign(S s) { S tmp <== *this; // bitcopy *this into tmp *this <== s; // bitcopy s into *this tmp.~this(); // call destructor on tmp return this; } It seems to be something new in D 2.012. Does it work? How?It's pseudo-code. There is no <== operator nor .~this() in D. I probably made a mistake in presenting it this way, but I was trying to show what was going on. The comments explain what is happening.
Mar 07 2008
"Aarti_pl" wrote in messageDid you notice this example in docs? (http://www.digitalmars.com/d/2.0/struct.html#AssignOverload) S* opAssign(S s) { S tmp <== *this; // bitcopy *this into tmp *this <== s; // bitcopy s into *this tmp.~this(); // call destructor on tmp return this; } It seems to be something new in D 2.012. Does it work? How? BR Marcin Kuszczak (aarti_pl)After reading this new feature, I'm really confused. I like the feature, but I'm not sure how it works, or why there are two functions for the same thing. How does one use the postblit, and how does one use the opAssign? It seems they both serve the same function, but opAssign allows more control possibly? And does opAssign get called if the postblit doesn't exist or vice versa? Not to knock what you have done, but it would seem to me more reasonable to have a single method, and if you wanted to blit the values before your custom code, just do: S* opAssign(ref const S s) { *this = s; ... } And this would get called on both copy construction and assignment. The way I see it now (if each are individual operations), blitting won't work if the source is const and contains a pointer, so that the following confusing situation happens: struct S { int[] buf this(this) { buf = buf.dup; } S* opAssign(ref const S s) { buf = s.buf.dup; return this; } } const S s; S t = s; // fails because the blit fails S u; u = s; // works because no blit occurred Also it appears that your "equivalent" statement is wrong, or else the opAssign signature is wrong: t = S.opAssign(s); Doesn't t need to be a struct pointer? Or else is opAssign not really returning a struct pointer? Does this work? S u; u = t = s; Finally, I don't understand the reasoning for tmp. It appears to be an unused part of the default opAssign... -Steve
Mar 07 2008
Steven Schveighoffer pisze:After reading this new feature, I'm really confused. I like the feature, but I'm not sure how it works, or why there are two functions for the same thing.Well, it occurred that this example was just a strange kind of "pseudo code" from Walter (please read the whole thread). I hope he will changed it in docs as it is really confusing. Best Regards Marcin Kuszczak (aarti_pl)
Mar 07 2008