title: Passing temporaries as non-const references in C++
body: <p>I have the following piece of code, as an example dec_proxy attempts to reverse the effects of the increment operator upon the type that is executed in a complex function call foo - which btw I cannot change the interface of. </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  template&lt;typename T&gt;
  class dec_proxy
  {
  public:
     dec_proxy(T&amp; t)
     :t_(t)
     {}
  
     dec_proxy&lt;T&gt;&amp; operator++()
     {
        --t_;
        return *this;
     }
  
  private:
     T&amp; t_;
  };
  
  template&lt;typename T, typename S, typename R&gt;
  void foo(T&amp; t, S&amp; s, R&amp; r)
  {
    ++t;
    ++s;
    ++r;
  }
  
  int main()
  {
     int i = 0;
     double j = 0;
     short  k = 0;
  
     dec_proxy&lt;int&gt; dp1(i);
     dec_proxy&lt;double&gt; dp2(j);
     dec_proxy&lt;short&gt; dp3(k);
  
     foo(dp1,dp2,dp3);
  
     //foo(dec_proxy&lt;int&gt;(i),     &lt;---- Gives an error
     //   dec_proxy&lt;double&gt;(j),     &lt;---- Gives an error
     //   dec_proxy&lt;short&gt;(k));      &lt;---- Gives an error 
  
     std::cout &lt;&lt; "i=" &lt;&lt; i &lt;&lt; std::endl;
  
     return 0;
  }
  </code></pre>
  
  <p>The problem is that for the various types I'd like to use dec_proxy I currently require creating a specialized instance of dec_proxy - it seems like a very messy and limited approach. </p>
  
  <p>My question is: What is the correct way to pass such short-lived temporaries as non-const reference parameters?</p>