Examples of C++ classes not binary moveable
<p>Does anyone know of <strong>any</strong> C++ class which are not binary moveable?</p>

<p>In other words, do you know <strong>any</strong> class where this results in memory-leak or undefined behaviour?</p>

<pre><code>{ // New scope
// Allocate some memory
unsigned char data1[sizeof(MyClass)];
unsigned char data2[sizeof(MyClass)];
// Create an instance of the class
::new (data1) MyClass();
// Create a pointer and run some class-specific code
MyClass* ptr = (MyClass*) data1;
ptr-&gt;MyFunction();
// Binary move everything to data2
::memcpy((void*)data2, (void*)data1, sizeof(MyClass));
::memset((void*)data1, sizeof(MyClass), 0); // for clarification
// Run some code at the new memory location, same object
ptr = (MyClass*) data2;
ptr-&gt;MyFunction();
// Run destructor at memory location2
(&amp;*data2)-&gt;~MyClass(); 
} // ... out of scope. No implicit destructors called. No memory leaks.
</code></pre>

<p><em>Update</em>:</p>

<ol>
<li><p>By binary moveable I mean any object which can be binary moved to another location in memory and still function properly (the move constructor could be implemented with memcpy()).</p></li>
<li><p>Of course any object which has pointers pointing to them cant be moveable, that's not part of the question.</p></li>
<li><p>(clarify) tr1::smart_ptr, std::deque, std::vector and std::list and like classes <em>can</em> be binary moveable so dont bother arguing about thier internal behaviour when reallocating nodes.</p></li>
<li><p>(clarify) Classes handling memory allocation can be binary movable, as a binary <em>move</em> means you are not handling both objects after the move, and the destructor wont be called twice.</p></li>
</ol>
