title: Too many copies when binding variadic template arguments
body: <p>I'm creating a job queue. The job will be created in thread A, then the job will be sent to thread B and thread B will do the job. After the job has been done, the job will be sent back to thread A.</p>
  
  <pre><code>#include &lt;functional&gt;
  #include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  using namespace std;
  
  template&lt;typename T, typename... Args&gt;
  class Job
  {
      public:
          Job(std::weak_ptr&lt;T&gt; &amp;&amp;wp, std::function&lt;void(const Args&amp;...)&gt; &amp;&amp;cb)
              : _cb(std::move(cb)), 
                _cbWithArgs(), 
                _owner(std::move(wp)) {}
  
      public:
          template&lt;typename... RfTs&gt;
          void bind(RfTs&amp;&amp;... args)
          {
              // bind will copy args for three times.
              _cbWithArgs = std::bind(_cb, std::forward&lt;RfTs&gt;(args)...);
          }
  
          void fire()
          {
              auto sp = _owner.lock();
              if (sp)
              {
                  _cbWithArgs();
              }
          }
  
      private:
          std::function&lt;void(const Args&amp; ...)&gt; _cb;
          std::function&lt;void()&gt; _cbWithArgs;
          std::weak_ptr&lt;T&gt; _owner;
  };
  
  struct Args
  {
      Args() = default;
      Args(const Args &amp;args)
      {
          cout &lt;&lt; "Copied" &lt;&lt; endl;
      }
  };
  
  struct Foo
  {
      void show(const Args &amp;)
      {
          cout &lt;&lt; "Foo" &lt;&lt; endl;
      }
  };
  
  int main()
  {
      using namespace std::placeholders;
  
      shared_ptr&lt;Foo&gt; sf (new Foo());
      Args args;
  
      // Let's say here thread A created the job.
      Job&lt;Foo, Args&gt; job(sf, std::bind(&amp;Foo::show, sf.get(), _1));
  
      // Here thread B has finished the job and bind the result to the
      // job. 
      job.bind(args);
  
      // Here, thread A will check the result.
      job.fire();
  }
  </code></pre>
  
  <p>The above codes compiles and works. But it gives the following results (g++ 4.8.4 &amp; clang have the same results):</p>
  
  <pre><code>Copied
  Copied
  Copied
  Foo
  </code></pre>
  
  <p>There are three copies! Not acceptable, I don't know where I did wrong. Why three copies? I googled and find a method from here: <a href="https://stackoverflow.com/a/16868401">https://stackoverflow.com/a/16868401</a>, it only copys params for one time. But it has to initialize the bind function in constructor.</p>
  
  <p>Thanks, Piotr Skotnicki. Unfortunately, I don't have a C++14 compiler. So, let's make the Args movable:</p>
  
  <pre><code>struct Args
  {
      Args() = default;
      Args(const Args &amp;args)
      {
          cout &lt;&lt; "Copied" &lt;&lt; endl;
      }
      Args(Args &amp;&amp;) = default;
      Args&amp; operator=(Args &amp;&amp;) = default;
  };
  </code></pre>
  
  <p>Now, it copys just one time :)</p>
  
  <p>Finally, I adopted the codes from this thread <a href="https://stackoverflow.com/a/16868151/5459549">https://stackoverflow.com/a/16868151/5459549</a>. The template gen_seq is true ART, I must say.</p>