How should std::map be used with a value that does not have a default constructor?
<p>I've got a value type that I want put into a map.
It has a nice default copy constructor, but does not have a default constructor.</p>

<p>I believe that so long as I stay away from using <code>operator[]</code> that everything will be OK.</p>

<p>However I end up with pretty ugly constructs like this to actually insert an object.
(I think insert just fails if there is already a value for that key).</p>

<pre><code>// equivalent to m[5]=x but without default construction

std::map&lt;int,X&gt;::iterator it = m.find(5);
if( it != m.end() )
{
   m-&gt;second = x;
}
else
{
  m-&gt;insert( std::make_pair(5,x) );
}
</code></pre>

<p>Which I believe will scan the map twice, and also looks pretty ugly.</p>

<p>Is there a neater / more efficient way to do this?</p>
