title: C++ move semantics and built-in types
body: <p>I am trying to understand move semantics using the following code.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;utility&gt;
  using namespace std;
  
  class A 
  {
     public:
     int a;
     A():a{1}{}
     A(A&amp;&amp; rref):a{rref.a}{cout&lt;&lt;"move constructor called"&lt;&lt;endl;}
     A(const A&amp; ref):a{ref.a}{cout&lt;&lt;"copy constructor"&lt;&lt;endl;}
  };
  
  int main(){
  
    A original; // original object
  
    cout&lt;&lt;"original.a = "&lt;&lt;original.a&lt;&lt; "|  address original.a="&lt;&lt; &amp;(original.a)&lt;&lt;endl;
  
    A movedto (std::move(original)); // calls A(A&amp;&amp;)
  
    cout&lt;&lt;"original.a = "&lt;&lt;original.a&lt;&lt; "| address original.a"&lt;&lt; &amp;(original.a)&lt;&lt;endl;
    cout&lt;&lt;"movedto.a = "&lt;&lt;movedto.a&lt;&lt;"| address movedto.a"&lt;&lt; &amp;(movedto.a)&lt;&lt;endl;
  
    return 0;
  }
  </code></pre>
  
  <p>Which give the following output</p>
  
  <pre><code>original.a = 1|  address original.a=0x7fff1611b6d0
  move constructor called
  original.a = 1| address original.a0x7fff1611b6d0
  movedto.a = 1| address movedto.a0x7fff1611b6e0
  </code></pre>
  
  <p>As it can be seen, the address of <code>original.a</code> and <code>movedto.a</code> are different, hence the member <code>a</code> underwent a copy operation in <code>A(A&amp;&amp; rref):a{rref.a}</code>.</p>
  
  <p>I am aware that <em>move</em> degrades to <em>copy</em> for built-in types. My question is that <strong>what do I do if I want to hijack (not copy) an instance of the class such as this one</strong>. Assume that I have 100 members (instead of just one) of built-in type, making copy expensive.</p>
  
  <p>One obvious way would be to store the object on the heap and use reference semantics to pass it around. But would like to stay with value semantics and still be able to circumvent the copying. </p>