title: Passing reference_wrapper objects as function arguments in C++11
body: <p>How does one pass and operate on constant (or non constant) references inside STL containers. Say I have a function:</p>
  
  <pre><code>bool foo(const Obj&amp; A, const Obj&amp; B) {
    // do some computation on A &amp; B
  }
  </code></pre>
  
  <p>and since A &amp; B always occur together, I would like to put them in an STL pair:</p>
  
  <pre><code>bool foo(const  std::pair&lt;Obj, Obj&gt;&amp; A_and_B) {
    // do some computation on A &amp; B
  }
  </code></pre>
  
  <p>However now both objects A &amp; B get copied into a pair every time foo needs to be called. Looking around I found reference_wrapper in C++11. Though doing something like this doesn't quite work:</p>
  
  <pre><code>bool foo(const  std::pair&lt;std::reference_wrapper&lt;Obj&gt;, std::reference_wrapper&lt;Obj&gt;&gt;&amp; A_and_B) {
    // do some computation on A &amp; B
  }
  
  bool foo(const  std::pair&lt;Obj, Obj&gt;&amp; A_and_B) {
    foo(std::make_pair(std::ref(A_and_B.first), std::ref(A_and_B.second)));
  }
  </code></pre>
  
  <p>What is the correct way of passing containers with reference values without using pointers?</p>