title: can memcpy() be used to change "const" member data?
body: <p>For a <code>struct</code> with <code>const</code> members</p>
  
  <pre><code>struct point { const int x; const int y; };
  </code></pre>
  
  <p>that is used as member data</p>
  
  <pre><code>struct Foo
  {
      point pt{ 0, 0 };
      void move_x(int value);
  };
  </code></pre>
  
  <p>How can <code>Foo::move_x()</code> be written to update <code>Foo::pt</code>?  Is it OK to use <code>memcpy()</code>?</p>
  
  <pre><code>#include &lt;memory.h&gt;
  void Foo::move_x(int value)
  {
      const point pt_{ pt.x + value, pt.y };
      (void) memcpy(&amp;pt, &amp;pt_, sizeof(pt_)); // pt = pt_;
  }
  </code></pre>
  
  <p>This can be safely done using a pointer</p>
  
  <pre><code>#include &lt;memory&gt;
  struct Bar
  {
      std::unique_ptr&lt;point&gt; pPt_{ new point{ 0, 0 } };
      const point&amp; pt() const {
          return *pPt_;
      }
  
      void move_x(int value) {
          pPt_.reset(new point{ pt().x + value, pt().y });
      }
  };
  </code></pre>
  
  <p>but the <code>point</code> is then always stored on the heap rather than in <code>Bar</code>.</p>
  
  <p>Note that clients don't really care about <code>point</code> at all:</p>
  
  <pre><code>   Foo foo;
     foo.move_x(314); // (314, 0)
  
     Bar bar;
     bar.move_x(3141); // (3141, 0)
  </code></pre>