title: Boost Variant: how to get currently held type?
body: <p>As I understood all types of <a href="http://www.boost.org/doc/libs/1_48_0/doc/html/variant.html" rel="noreferrer">boost.variant</a> are parsed into real types (meaning as if boost <code>variant&lt;int, string&gt; a; a="bla-bla"</code> would after compilation turn into <code>string a; a="bla-bla"</code>) And so I wonder: how to get what type was put into boost variant? </p>
  
  <p>What have I tried:</p>
  
  <pre><code>#include &lt;boost/variant.hpp&gt;
  #include &lt;boost/function.hpp&gt;
  #include &lt;boost/shared_ptr.hpp&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
      typedef boost::function&lt;double (double x)&gt; func0;
      typedef boost::function&lt;double (double x, double y)&gt; func1;
      typedef boost::variant&lt;int, func0, func1&gt; variant_func;
      func1 fn = std::plus&lt;double&gt;();
      variant_func v(fn);
      std::cout &lt;&lt; boost::get&lt;func1&gt;(v)(1.0, 1.0) &lt;&lt; std::endl; // this works
      //std::cout &lt;&lt; boost::get&lt;v::type&gt;(v)(1.0, 1.0) &lt;&lt; std::endl; // this does not compile with many errors
      // std::cout &lt;&lt; (v)(1.0, 1.0) &lt;&lt; std::endl; // this fails with Error    1   error C2064: term does not evaluate to a function taking 2 arguments
  
      std::cin.get();
      return 0;
  }
  </code></pre>