Returning a reference to an object owned by a data structure
<p>My set:</p>

<pre><code>std::set&lt;Object&gt; objects;
</code></pre>

<p>I want find a object and return it as a reference, also inserting it if it doesn't exist:</p>

<pre><code>const Object&amp; get(params...){
    Object obj(params...);
    std::set&lt;Object&gt;::const_iterator i = objects.find(obj);
    if(i != objects.end())
        return *i;
    objects.insert(obj);
    return * objects.find(obj);
}
</code></pre>

<p>This can result in a segmentation fault or this will work always?</p>
