title: How to copy a non-trivial c++ union?
body: <p>I'm trying to convert the following data structure:</p>
  
  <pre><code>template&lt;typename ValueT, typename ChildT&gt;
  class MyUnion 
  {
  public:
      MyUnion() : mChild(NULL) {}
  private:
      union {
          ChildT* mChild;
          ValueT* mValue;
      };
  };
  </code></pre>
  
  <p><code>ValueT</code> can be both POD (<code>int</code>, <code>float</code>, etc) and non-trivial stuff like <code>Vec3</code>, <code>std::string</code> which is the reason it was initially implemented as a pointer to dynamically allocated memory. However, with c++11 we can now store the value directly in the class. The result I'm looking for is this:</p>
  
  <pre><code>template&lt;typename ValueT, typename ChildT&gt;
  class MyUnion 
  {
  public:
      MyUnion() : mChild(NULL) {}
  private:
      union {
          ChildT* mChild;
          ValueT mValue;
      };
  };
  </code></pre>
  
  <p>Changing this makes the compiler complain that the copy constructor is missing, so I want to implement</p>
  
  <pre><code>MyUnion(const MyUnion&amp; other);
  MyUnion&amp; operator=(const MyUnion&amp; other);
  </code></pre>
  
  <p>and ideally the move constructors also. Previously the compiler implemented these for me. With POD I could do a <code>memcpy</code> or something similar -- can I use the same now and expect correct outcome?</p>