How can I optimize the construction of a pair in this case?
<p>I have a </p>

<pre><code>template&lt;class Key, class Value, class Comp = std::less&lt;Key&gt; &gt; class MyContainer;
</code></pre>

<p>which is implemented with a tree of nodes internally, where each node type is defined as below:</p>

<pre><code>typedef std::pair&lt;Key, Value&gt; Node;
</code></pre>

<p>To erase one element from the container I need to provide the following method to the user:</p>

<pre><code>void MyContainer::erase(const Key&amp; k) {
   const Node n(k, default_value); // default_value is a data member, copied from Value() by default in the constructor of MyContainer
   //...
   mytree-&gt;remove(n); // search and remove the Node in case
}
</code></pre>

<p>The tree uses (a wrapper class derived from) <code>less&lt;Key&gt;</code> to compare and sort the elements in the tree.</p>

<p>As you might understand, the <code>remove()</code> method in the tree does not really need to access the second element of the pair to find the node. For this reason I would like to avoid the overhead of the copy of <code>default_value</code> to the second element of the <code>pair</code>.</p>

<p>Is there a way to get rid of this unnecessary overhead?</p>

<p>Edit: The type of the tree is given as </p>

<pre><code>template&lt;class T, class Comp = std::less&lt;T&gt; &gt; class Tree;
</code></pre>
