title: Is there generic way to mirror a pair (pair<A,B> to pair<B,A>)?
body: <p>for example, to mirror a <code>pair &lt; int , float &gt;</code> to <code>pair &lt; float , int &gt;</code>, I can create a template function like this:</p>
  
  <pre><code>template&lt;class AB,class BA&gt;
  void mirror(const AB&amp; ab,BA&amp; ba){
      ba.first=ab.second;
      ba.second=ab.first;
  }
  
  int main(){
      pair&lt;int,float&gt; ab;
      ab.first=3;
      ab.second=2.0;
      pair&lt;float,int&gt; ba;
      mirror&lt;decltype(ab),decltype(ba)&gt;(ab,ba);
      printf("%d\n",ba.second);
      return 0;
  }
  </code></pre>
  
  <p>but this method cannot handle a pair in another pair, e.g.:</p>
  
  <p><code>pair &lt; bool , pair&lt; int , float &gt; &gt;</code> to <code>pair &lt; pair &lt; float , int &gt; , bool &gt;</code>:</p>
  
  <pre><code>pair&lt;bool,pair&lt;int,float&gt; &gt; a_bc;
  pair&lt;pair&lt;float,int&gt;,bool&gt; cb_a;
  mirror&lt;decltype(a_bc),decltype(cb_a)&gt;(a_bc,cb_a);
  </code></pre>
  
  <p><code>pair &lt; pair &lt; A , B &gt;, pair &lt; C , D &gt; &gt;</code> to <code>pair &lt; pair &lt; D , C &gt; , pair&lt; B , A &gt; &gt;</code>:</p>
  
  <pre><code>pair&lt;pair&lt;A,B&gt;,pair&lt;C,D&gt; &gt; ab_cd;
  pair&lt;pair&lt;D,C&gt;,pair&lt;B,A&gt; &gt; dc_ba;
  mirror&lt;decltype(ab_cd),decltype(dc_ba)&gt;(ab_cd,dc_ba)
  </code></pre>
  
  <p>is it possible to write mirror template functions (e.g.:2 mirror function templates, one for pair, another for non-pair, then use recursion) functions which can handle all cases above?</p>