title: Generic function to convert boost::any to boost::variant
body: <p>Assume that you have a <code>boost::any</code> object and a <code>boost::variant</code> object.</p>
  
  <p>I'm looking for a generic function <code>convert</code>, that takes a template parameter T being a specialized <code>boost::variant</code> e.g. <code>boost::variant&lt;int, std::string&gt;</code> and magically converts the <code>boost::any</code> to one of the available types of the given <code>boost::variant</code>.</p>
  
  <pre><code>template&lt;T&gt;
  T convert(const boost::any&amp; any) {
     // Some generic conversion code here or throw exception if conversion is not possible!
  }
  
  int main(int argc, char** args) {
      typedef boost::variant&lt;int, std::string&gt; TVar;
  
      boost::any any="Hello World";
      TVar variant=convert&lt;TVar&gt;(any);
      // variant contains "Hello World"
      return 0;
  }
  </code></pre>
  
  <p>I'm wondering if it is possible to write such a function or if it might be impossible for some reason?</p>