
On Aug 20, 2011, at 10:45 AM, Olaf van der Spek wrote:
On Sat, Aug 20, 2011 at 6:28 PM, Mathias Gaunard <mathias.gaunard@ens-lyon.org> wrote:
You cannot use bitwise copy to implement move semantics. That just doesn't work.
Hmm, why not? What breaks if you do a bitwise swap?
Consider a type that looks contains a pointer to one of its member vars. struct Foo { char *curPos; char buffer [ 8 ]; Foo () : curPos (buffer+4) {} }; Foo a, b; Let's assume that a is at 0x1000, and b is at 0x2000 (and four byte pointers) 0x1000: 00001008 0x1004: aaaaaaaaa 0x1008: bbbbbbbb 0x2000: 00002008 0x2004: cccccccccc 0x2008: dddddddd Now we do a (bitwise) swap of a and b: 0x1000: 00002008 0x1004: cccccccccc 0x1008: dddddddd 0x2000: 00001008 0x2004: aaaaaaaaa 0x2008: bbbbbbbb a's pointer now points into b's buffer. -- Marshall Marshall Clow Idio Software <mailto:mclow.lists@gmail.com> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait). -- Yu Suzuki