title: C++ transfer ownership of a struct to a function
body: <p>Is it possible to transfer the ownership of a local variable in C++ (or C++0x) to a function, leaving it undefined after the return, so optimizations can be done?</p>
  
  <pre class="lang-c prettyprint-override"><code>struct A {
      int a[100000];
  };
  
  int func(A&amp; s){
      //s should now be "owned" by func and be undefined in the calling function
      s.a[2] += 4;
      return s.a[2];
  }
  
  int main(){
      A s;
      printf("%d\n", func(s));
      //s is now undefined
  }
  </code></pre>
  
  <p>I want the function "func" to be optimized to simply return s.a[2]+4, but not change the actual value in memory, just like if "s" had been a local variable in "func".
  If it can't be done in standard C++, is it possible with some extension in g++?</p>