title: How can I have a pair with reference inside vector?
body: <p>I really need to make <code>std::vector</code> of <code>std::pair</code> with reference (<code>&amp;</code>) inside, but it breaks inside the function when I try to <code>push_back</code> reference value. After debugging I discovered, that the address of reference is different from the address inside <code>unique_ptr</code> (but the value is the same). </p>
  
  <p>When I don't use (here the foo()) any function that insert into vector it's the value it refers to is correct, but the addresses still don't match.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  #include &lt;iterator&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  void foo(std::vector&lt;std::pair&lt;const int&amp;, int&gt; &gt;&amp; vector,         
  std::unique_ptr&lt;int&gt;&amp; ptr) {
      vector.push_back(std::make_pair&lt;const int&amp;, int&gt;(*ptr, 11));
  }
  
  int main() {
      std::vector&lt;std::pair&lt;const int&amp;, int&gt; &gt; v;
      std::unique_ptr&lt;int&gt; i = std::make_unique&lt;int&gt;(1);
      std::unique_ptr&lt;int&gt; b = std::make_unique&lt;int&gt;(0);   
      foo(v, i);
      v.push_back(std::make_pair&lt;const int&amp;, int&gt;(*b, 10));
      std::cout &lt;&lt; v.size() &lt;&lt; ": ";
      for (auto x : v) {
          std::cout &lt;&lt; x.first &lt;&lt; ",";
      }
      std::cout &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>This code demonstrates the problem - instead of <code>"2: 1,0,"</code> it outputs <code>"2: -342851272,0,"</code> (or similar big negative number in the first place).</p>
  
  <p>Where is the problem?</p>