title: How to dynamic_cast a variadic template with mismatch reference modifier in parameters?
body: <p>I have a class hierarchy where the base class contains a function which tests for <code>dynamic_cast</code> the <code>this</code> pointer into a derived template type based on the arguments it receive.</p>
  
  <p>Problem is that <code>dynamic_cast</code> operator checks for exact match of the arguments, taking into account if they are ref or not. I need the following example to work on both cases, is there a way to do so?</p>
  
  <pre><code>template &lt;typename... P&gt;
  struct Derived;
  
  struct Base
  {
      virtual ~Base() {}
  
      template &lt;typename... P&gt;
      void doCast(P&amp;&amp;... p) {
          Derived&lt;P...&gt; *res=dynamic_cast&lt;Derived&lt;P...&gt; *&gt;(this);
          if (!res)
              std::cout&lt;&lt;"Failed."&lt;&lt;std::endl;
          else {
              std::cout&lt;&lt;"Success."&lt;&lt;std::endl;
              res-&gt;doSomethingWithP(std::forward&lt;P&gt;(p)...);
          }
      }
  };
  
  template &lt;typename... P&gt;
  struct Derived: public Base
  {
      void doSomethingWithP(P... p) {
          /*Whatever, doesn't matter*/
      }
  };
  
  int main(int argc, char **argv)
  {
      Derived&lt;int, int, int&gt; derived;
      Base *b=&amp;derived;
  
      int x=10;
      int y=20;
      int z=30;
  
      //The two calls must succeed.
      b-&gt;doCast(x,y,z); //Failed.
      b-&gt;doCast(10,20,30); //Success.
  
      return 0;
  }
  </code></pre>
  
  <p><code>Derived</code> can accept types that are both values, references, and pointers - <em>cv</em>-qualified or not. </p>