title: Is it possible to std::move objects out of functions? (C++11)
body: <p>This program tries to move a string out of a function and use it for the construction of another string:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;utility&gt;
  
  std::string &amp;&amp; Get_String(void);
  
  int main(){
  
      std::string str{Get_String()};
      std::cout &lt;&lt; str &lt;&lt; std::endl;
  
      return 0;
  }
  
  std::string &amp;&amp; Get_String(void){
  
      std::string str{"hello world"};
  
      return std::move(str);
  }
  </code></pre>
  
  <p>The program compiles, but segfaults upon execution.  </p>
  
  <hr>
  
  <p>This was my rationale:  <code>Get_String</code> will create a local string.  A copy of that string will need to be made and returned before the string goes out of scope.  That copy will be used to construct the string in main. However, If I moved the the string out of the function, no copy would need to be made. </p>
  
  <p>In an attempt to understand move semantics, could someone explain why what I'm doing, probably makes no sense.  Is it possible to move objects out of a function?  </p>
  
  <hr>
  
  <p><strong>EDIT:</strong><br>
  It compiles and runs correctly if I change the function signature from:  </p>
  
  <pre><code>std::string &amp;&amp; Get_String(void);
  </code></pre>
  
  <p>to</p>
  
  <pre><code>std::string Get_String(void);  
  </code></pre>
  
  <p>Is it still more efficient to move the string during the return in this case?</p>