title: Advantages of returning by reference?
body: <p>I came across the code, where in a class one of the member function returns by reference. What are the advantages of doing it like that? E.g.:</p>
  <pre><code>class SomeClass {
      std:vector&lt;int&gt; some_vals;
      // some functions that modify some_vals
  public:
      const std::vector&lt;int&gt;&amp; get_some_vals() const { return some_vals; }
  };
  </code></pre>
  <p>And then when the function is used:</p>
  <pre><code>SomeClass my_obj;
  const vector&lt;int&gt;&amp; some_vals = my_obj.get_some_vals();
  </code></pre>
  <p>What is the advantage of doing it like this instead of just returning std::vector?</p>