title: boost::any, variants, calling functions based on arrays of them
body: <p>Given a set of functions, such as:
  <code><pre>
  template&lt;class A1>
  Void Go(A1 a);</p>
  
  <p>template&lt;class A1, class A2>
  Void Go(A1 a1, A2 a2);</p>
  
  <p>template&lt;class A1, class A2, class A3>
  Void Go(A1 a1, A2 a2, A3 a3);
  </pre></code>
  Is it possible to take an array of some variant type and given its contents, fire the correct function?   My application for this is that I want to pass a set of parameters X, to another process, where I only have the option of passing a single pointer.  My idea was to send a pointer to a std::vector&lt;boost::any> and then to somehow work out which of the above methods to fire given its contents.  </p>
  
  <p>This concerns my experiments with cross-thread eventing and communication, hence it may seem unnecessarily esoteric!</p>
  
  <p>Edit:  ok, for example, this is the intention.  Obviously it doesn't compile (the template resolution occurs at compile-time, but I want to determine which function to call at run-time!):</p>
  
  <pre><code>
  
  #include &lt;boost\any.hpp>
  
  #include &lt;vector>
  #include &lt;iostream>
  #include &lt;string>
  
  
  class A
  {
  
  public:
  
      void Go()
      {
          std::cout &lt;&lt; L"(0 params)\n";
      }
  
      template
      void Go(U0 u0)
      {
          std::cout &lt;&lt; L"1 param " &lt;&lt; u0 &lt;&lt; L"\n";  
      }
  
      template
      void Go(U0 u0, U1 u1)
      {
          std::cout &lt;&lt; L"2 params " &lt;&lt; u0 &lt;&lt; L" " &lt;&lt; u1 &lt;&lt; L"\n";   
      }
  
      template
      void Go(U0 u0, U1 u1, U2 u2)
      {
          std::cout &lt;&lt; L"3 params " &lt;&lt; u0 &lt;&lt; L" " &lt;&lt; u1 &lt;&lt; L" " &lt;&lt; u2 &lt;&lt; L"\n"; 
      }
  
  };
  
  class B
  {
  
  public:
  
      void Whatever() {}
  
  };
  
  int main(int argc, wchar_t* argv[])
  {
      // Create a collection of variants.
  
      std::vector&lt;boost::any> myVariants;
  
      B myB;
  
      myVariants.push_back(123);
      myVariants.push_back(std::wstring(L"Test"));
      myVariants.push_back(&myB);
  
  
  
      // Take a void pointer to them.
  
      void *variants = &myVariants;
  
  
  
      // Convert back into an array.
  
      std::vector&lt;boost::any>& myConverted = *(std::vector&lt;boost::any> *)(variants);
  
  
  
      // Fire the correct event on A.
  
      A myA;
  
      switch(myConverted.size())
      {
      case 0:
          myA.Go();
          break;
  
      case 1:
          myA.Go(myConverted[0]);
          break;
  
      case 2:
          myA.Go(myConverted[0], myConverted[1]);
          break;
  
      case 3:
          myA.Go(myConverted[0], myConverted[1], myConverted[2]);
          break;
  
      default: ;
          // throw
      }
  }
  
  </code></pre>