title: Return a const reference or a copy in a getter function?
body: <p>What's better <em>as default</em>, to return a copy (1) or a reference (2) from a getter function?</p>
  
  <pre><code>class foo {
  public:
      std::string str () { // (1)
          return str_;
      }
  
      const std::string&amp; str () { // (2)
          return str_;
      }
  
  private:
      std::string str_;
  };
  </code></pre>
  
  <p>I know 2) could be faster but don't have to due to (N)RVO. 1) is safer concerning dangling references but the object will probably outlife or the reference is never stored.</p>
  
  <p>What's your default when you write a class and don't know (yet) whether performance and lifetime issues matter?</p>
  
  <p>Additional question: Does the game change when the member is not a plain string but rather a vector?</p>