title: Combining dynamic_cast and std::any_cast
body: <p>Is there any safe <code>std::any_cast</code> and <code>dynamic_cast</code> combination?</p>
  <p>I'm trying to perform the following:</p>
  <pre><code>struct V
  {
      virtual void x( ) { std::cout &lt;&lt; &quot;V&quot;; }
  };
  
  struct A: V
  {
      void x( ) override { std::cout &lt;&lt; &quot;A&quot;; }
  };
  
  struct B: V
  {
      void x( ) override { std::cout &lt;&lt; &quot;B&quot;; }
  };
  
  struct C: A, B
  {
      void x( ) override { std::cout &lt;&lt; &quot;C&quot;; }
  };
  
  int main( )
  {
      // In my code, I cannot change the template argument
      // to be a base class and construct it with a child
      // class due to requirements of my implementation
      auto c = std::make_any&lt; C &gt;( );
  #if 0 // doesn't work
      std::any_cast&lt; B &gt;( c ).x( );
      std::any_cast&lt; A &gt;( c ).x( );
  #else // works, but requires knowing the type is C
      dynamic_cast&lt; B &amp;&amp; &gt;( std::any_cast&lt; C &gt;( c ) ).x( );
      dynamic_cast&lt; A &amp;&amp; &gt;( std::any_cast&lt; C &gt;( c ) ).x( );
  #endif
  }
  </code></pre>