title: Move operator with templates
body: <p>I have a templated class that I want to avoid copying (because of the potential cost to do so). I can implement a move constructor, but I would also like to allow moving "accross template parameter". Here is what I'm trying to compile:</p>
  
  <pre><code>template &lt;class T&gt;
  class Foo
  {
  public:
      Foo() {}
      template &lt;class U&gt; Foo(Foo&lt;U&gt;&amp;&amp;) {}
  
  private:
      Foo(const Foo&amp;);
  };
  
  Foo&lt;int&gt; f() { Foo&lt;float&gt; y; return move(y); }
  Foo&lt;int&gt; g() { Foo&lt;int&gt; x; return x; }
  Foo&lt;int&gt; h() { Foo&lt;float&gt; z; return z; }
  </code></pre>
  
  <p>I understand why technically f compiles: the type of move(y) is Foo(float)&amp;&amp; and there happens to be a handy constructor that takes a Foo(U)&amp;&amp;, so the compiler manages to find that U=float works.</p>
  
  <p>h doesn't compile. z is of type Foo(float) and I guess that's too far from Foo(U)&amp;&amp; to figure out that the move constructor can be invoked if U=float is chosen...</p>
  
  <p>I'm not sure why g compiles, but it does. The type of x is Foo(int). How does the compiler manage to use the move operator (it can't just implicit cast from Foo(int) to Foo(int)&amp;&amp;, can it?)</p>
  
  <p>So my questions are: what are the rules? why does h compiles but g doesnt? is there something I can change in Foo to make h compile?</p>
  
  <p>Thank you</p>