title: memcpy'ing std::string in C++
body: <p>For the Eigen matrix library, someone filed the following issue:</p>
  
  <p><a href="https://forum.kde.org/viewtopic.php?f=74&amp;t=140169" rel="nofollow noreferrer">https://forum.kde.org/viewtopic.php?f=74&amp;t=140169</a></p>
  
  <p>As I understand, the problem was that you cannot do a memcpy-based swap of two std::strings.</p>
  
  <p>memcpy'ing here doesn't really seem advisable, but I also don't understand the problem the reporter is identifying.</p>
  
  <p>It seems like if std::string is conceptually:</p>
  
  <pre><code>class string
  {
      union
      {
          class heap_str_
          {
              char* str_;
              size_t len_;
          }
          char small_str[16];
      }
  
  };
  </code></pre>
  
  <p>I think both of these would be okay under a memcpy (?) (ownership issues not withstanding, which I guess would be 'okay' with a swap).</p>
  
  <p>What am I missing here?</p>