title: swap temporary tuples of references
body: <p>I'm writing a custom iterator that, when dereferenced returns a tuple of references.  Since the tuple itself is ephemeral, I don't think I can return a reference from operator*().  I think my iterator makes sense semantically, since it has reference semantics, even though operator* returns a value.</p>
  
  <p>The issue is, when I try to call std::swap (or rather, when std::sort does), like below, I get errors because the swap expects l-values.  Is there an easy fix to this problem?</p>
  
  <pre><code>#include &lt;vector&gt;
  
  class test {
    public:
    test()
      :v1(10), v2(10)
    {}
  
    class iterator {
      public:
      iterator(std::vector&lt;int&gt;&amp; _v1,
               std::vector&lt;int&gt;&amp; _v2)
        :v1(_v1), v2(_v2){}
  
      std::tuple&lt;int&amp;, int&amp;&gt; operator*(){
        return std::tuple&lt;int&amp;, int&amp;&gt;{v1[5], v2[5]};
      }
      std::vector&lt;int&gt;&amp; v1;
      std::vector&lt;int&gt;&amp; v2;
    };
  
    std::vector&lt;int&gt; v1, v2;
  };
  
  
  
  int main(){
    test t;
    //error, Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/type_traits:3003:1: note: candidate function [with _Tp = std::__1::tuple&lt;int &amp;, int &amp;&gt;] not viable: expects an l-value for 1st argument
  
    //deep within the bowels of std::sort ...
    std::swap(*(test::iterator(t.v1, t.v2)),
              *(test::iterator(t.v1, t.v2)));
  }
  </code></pre>