title: boost::variant implementation
body: <p>I'm just curious about <code>boost::variant</code>'s implementation.</p>
  
  <p>Does it work like this?</p>
  
  <p>Two members:</p>
  
  <ol>
  <li>A number representing the currently stored type (i.e. 0 for the first template parameter, 1 for the second template parameter etc)  </li>
  <li>A union of all possible types (which of course the size of the largest).</li>
  </ol>
  
  <p><code>apply_visitor()</code>:</p>
  
  <p>Has a <code>switch</code> statement on the number representing the currently stored type to call the correct overload (this would in the worse case be compiled as jump table so take constant time).</p>
  
  <p>I understand there's also there are a number of optimisations which can sure <code>boost::variant</code> does not need to dynamically allocate memory as detailed <a href="http://www.boost.org/doc/libs/1_52_0/doc/html/variant/design.html#variant.design.never-empty.optimizations" rel="nofollow noreferrer">here</a>, but I think I get these.</p>