title: Determine Parent Class from boost::any
body: <p>May I know is there any way to determine parent class from boost::any?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/any.hpp&gt;
  
  class a {
  public:
      virtual ~a() {}
  };
  
  class b : public a {
  };
  
  bool is_class_a(const boost::any&amp; any)
  {
      return boost::any_cast&lt;a&gt;(&amp;any) != 0;
  }
  
  bool is_class_a_v2(const boost::any&amp; any)
  {
      try
      {
          boost::any_cast&lt;a&gt;(any);
          return true;
      }
      catch(const boost::bad_any_cast &amp;)
      {
          return false;
      }
  }
  
  int main()
  {
      std::cout&lt;&lt; is_class_a(b())&lt;&lt; std::endl;    // return 0. but i wish to return 1.
      std::cout&lt;&lt; is_class_a(a())&lt;&lt; std::endl;    // return 1.
  
      std::cout&lt;&lt; is_class_a_v2(b())&lt;&lt; std::endl; // return 0. but i wish to return 1.
      std::cout&lt;&lt; is_class_a_v2(a())&lt;&lt; std::endl; // return 1.
  }
  </code></pre>