Best practice way to store collection
<p>I am porting a C# application to C++, and I have the following class (where Box is a struct, and the BoxStore will be a global, long living object in the app):</p>

<pre><code>public class BoxStore
{
    private List&lt;Box&gt; boxes;

    ...

    public List&lt;Box&gt; GetBoxes()
    {
        return this.boxes;
    }
}
</code></pre>

<p>I'm planning to store the boxes collection in a std::vector in C++. There are multiple ways to define the collection:</p>

<pre><code>std::vector&lt;Box&gt; boxes;
shared_ptr&lt;std::vector&lt;Box&gt;&gt; boxes;
std::vector&lt;Box&gt;&amp; boxes;
(*std::vector&lt;Box&gt; boxes;)
</code></pre>

<p>What is - if there is any - best way to go? I guess the last option (to store a raw pointer to the collection) is the worst solution without any benefit (hence the parantheses)).</p>

<p>And what is the best approach to port the GetBoxes method? Of course this depends on the way of storing the collection. I can see multiple approaches here too:</p>

<pre><code>(std::vector&lt;Box&gt; GetBoxes();)
std::shared_ptr&lt;std::vector&lt;Box&gt;&gt; GetBoxes();
*std::vector&lt;Box&gt; GetBoxes();
std::vector&lt;Box&gt;&amp; GetBoxes();
</code></pre>

<p>The first solution seems incorrect, because the vector would get copied upon return, thus the caller couldn't modify the original collection.<br>
However the other three approaches seem equally good to me. The BoxStore instance is long living, and is not getting destroyed while the app is running, so the caller won't have ownership over the collection. Does this mean, that returning a shared_ptr is semantically incorrect? (It is always the BoxStore object, who frees the collection.)</p>

<p>And is there a significant difference between returning a raw pointer or a reference?</p>
