title: Should my function return a pointer to std::vector, or a reference to std::vector?
body: <p>I have a <code>std::map&lt;int, std::vector&lt;SomeStruct&gt;&gt;</code>,<br>
  and provide a query like <code>std::vector&lt;SomeStruct&gt; FindData(int key)</code>. </p>
  
  <p>To prevent copying the whole data, I modify it to be <code>std::vector&lt;SomeStruct&gt;&amp; FindData(int key)</code>.<br>
  But, there will be no data for certain <code>key</code>, so sometimes I have nothing to return.<br>
  In that case, I declare a file scope variable that is an empty <code>std::vector&lt;SomeStruct&gt;</code> and return it.</p>
  
  <p>But if I choose the pointer to vector, that is <code>std::vector&lt;SomeStruct&gt;* FindData(int key)</code> then I can just return <code>NULL</code> for non-existing <code>key</code>.</p>
  
  <p>Which one is better?<br>
  I learned that pointer to <code>std::vector</code> is bad(or weird? not sure) in the question (<a href="https://stackoverflow.com/questions/15703842/is-there-other-syntax-for-this-pointer-operation/15703927?noredirect=1#comment22312516_15703927">Is there other syntax for this pointer operation?</a>)<br>
  And I personally like reference to <code>std::vector</code> too, so that I can use <code>operator[]</code> easier, but the drawback is I have to declare an additional empty variable for it.</p>
  
  <p>Code example are like: In <code>SomeClass.h</code></p>
  
  <pre><code>typedef std::vector&lt;SomeStruct&gt; DataVec;
  typedef std::map&lt;int, DataVec&gt; DataMap;
  DataMap m_DataMap;
  </code></pre>
  
  <p>Now In <code>SomeClass.cpp</code>:</p>
  
  <p>Case 1:</p>
  
  <pre><code>namespace
  {
      DataVec EmptyVector;
  }
  
  DataVec&amp; FindDatas(int key)
  {
      DataMap::iterator It = m_DataMap.find(key);
  
      if (It == m_DataMap.end()) return EmptyVec;
  
      return It-&gt;second;
  }
  </code></pre>
  
  <p>Case 2:</p>
  
  <pre><code>DataVec* FindDatas(int key)
  {
      DataMap::iterator It = m_DataMap.find(key);
  
      if (It == m_DataMap.end()) return NULL;
  
      return &amp;(It-&gt;second);
  }
  </code></pre>
  
  <p>Reference: <br>
  Pros: looks like normal <code>std::vector</code>.<br>
  Cons: Additional variable declared.</p>
  
  <p>Pointer: <br>
  Pros: Shorter query function and no need other variable.<br>
  Cons: looks weird(?!), and you can't juse <code>p[i]</code>, you have to <code>(*p)[i]</code>, which is annoying.</p>
  
  <p>Which one is better?</p>