title: How to use typelists
body: <p>I read about typelists in 'Modern C++ Design' and I understood it as some kind of union for types. By putting diffrent, non-related types in a typelist, one can use it to represent more than one type at once, without inheritance. I tested typelist in some simple functions with primitive types, but I couldn't get any of them to work.</p>
  
  <p>Could someone tell me if my unterstanding of typelists is right and give an simple real world example how to use typelists in every day average code? Thanks in advance.</p>
  
  <p>Btw, I'm using Windows and Visual Studio 2005 and its compiler.</p>
  
  <p>EDIT: my examples are gone, I use a sandbox project in vs to test those things. But it was quiet similar to code in Dobbs tutorial:</p>
  
  <pre><code>void SomeOperation(DocumentItem* p)
  {
      if (TextArea* pTextArea = dynamic_cast&lt;TextArea*&gt;(p))
      {
          ... operate on a TextArea object ...
      }
      else if (VectorGraphics* pVectorGraphics =
          dynamic_cast&lt;VectorGraphics*&gt;(p))
      {
          ... operate on a VectorGraphics object ...
      }
      else if (Bitmap* pBitmap = dynamic_cast&lt;Bitmap*&gt;(p))
      {
          ... operate on a Bitmap object ...
      }
      else
      {
          throw "Unknown type passed";
      }
  }
  </code></pre>
  
  <p>This works but I don't see the advantage over inheritance which is capable to do the same. And dynamic cast don't work on primitive types. Is it possible to use it as a return value like:</p>
  
  <pre><code>typedef Typelist&lt;int, string&gt; mylist
  mylist myfunction() {
      if(foo == bar)
          return 5;
  
      return "five";
  }
  </code></pre>