|
Boost : |
Subject: Re: [boost] [interest] underlying type library
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2011-08-20 14:13:40
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_at_[hidden]> 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_at_[hidden]>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk