title: C++ Rvalue arrgument and move
body: <p>Trying to understand the difference between rvalue formal parameter and call by value parameter.</p>
  
  <p>When I called fun(move(Demo{}) I see only default constructor called once. 
  While I called gun(move(Demo{}) I see default constructor and rval constructor called.  Please some one help me to understand the behaviour of &amp;&amp; formal argument type, uses of &amp;&amp; in functions/member functions.</p>
  
  <p>compilers clang++ , g++ , vc++ </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;utility&gt;
  #include &lt;type_traits&gt;
  
  using namespace std;
  
  class Demo {
      int i = 10;
  public:
      Demo(){
          i = 40;
      }
      Demo(Demo &amp;&amp; p) {
          i = p.i + 20;
          cout &lt;&lt; "I am in Demo &amp;&amp; " &lt;&lt; endl;
      }
      Demo &amp; operator = (Demo &amp; p) {
          cout &lt;&lt; "I am in operator &amp;&amp; " &lt;&lt; endl;
      }
      Demo &amp; operator = (Demo &amp;&amp; p) {
          i = p.i + 10;
          cout &lt;&lt; "I am in operator &amp;&amp; " &lt;&lt; endl;
      }
      ~Demo(){
          cout &lt;&lt; "I am in ~Demo " &lt;&lt; i &lt;&lt; endl;
      }
  };
  
  void fun(Demo &amp; d) {
      cout &lt;&lt; "fun( &amp;) " &lt;&lt; endl;
      cout &lt;&lt; " -- End --  " &lt;&lt; endl;
  }
  
  void fun(Demo &amp;&amp; d) {
      cout &lt;&lt; "fun( &amp;&amp; ) " &lt;&lt; endl;
      std::cout &lt;&lt; std::boolalpha;
      cout &lt;&lt; "Lvalur reference : " &lt;&lt; is_lvalue_reference&lt;decltype(d)&gt;::value &lt;&lt; endl;
      cout &lt;&lt; "Rvalue Refernce  : " &lt;&lt; is_rvalue_reference&lt;decltype(d)&gt;::value &lt;&lt; endl;
  
      cout &lt;&lt; " -- End --  " &lt;&lt; endl;
  }
  
  void gun(Demo d) {
      cout &lt;&lt; "gun( ) " &lt;&lt; endl;
      std::cout &lt;&lt; std::boolalpha;
      cout &lt;&lt; "Lvalur reference : " &lt;&lt; is_lvalue_reference&lt;decltype(d)&gt;::value &lt;&lt; endl;
      cout &lt;&lt; "Rvalue Refernce  : " &lt;&lt; is_rvalue_reference&lt;decltype(d)&gt;::value &lt;&lt; endl;
      cout &lt;&lt; " -- End --  " &lt;&lt; endl;
  }
  int main() {
      cout &lt;&lt; "Main begin " &lt;&lt; endl;
      fun(move(Demo{}));
      cout &lt;&lt; "------------------- " &lt;&lt; endl;
      gun(move(Demo{}));
      cout &lt;&lt; "Main End " &lt;&lt; endl;
  }
  </code></pre>
  
  <h1>//Output</h1>
  
  <pre>
  Main begin
  fun( && )
  Lvalur reference : false
  Rvalue Refernce  : true
   -- End --
  I am in ~Demo 40
  -------------------
  I am in Demo &&
  gun( )
  Lvalur reference : false
  Rvalue Refernce  : false
   -- End --
  I am in ~Demo 60
  I am in ~Demo 40
  Main End
  </pre>