title: Storing boost function
body: <p>I have to store a list of different <strong>boost::function</strong> objects. To provide this I'm using boost::any. I have a few functions which takes different functions signatures, pack them into <strong>any</strong> and then insert into special map with given type. Here is the code:</p>
  
  <pre><code>enum TypeEnumerator
  {
      e_int,
      e_float,
      e_double
  };
  
  typedef map&lt; string, pair&lt;any, TypeEnumerator&gt; &gt; CallbackType;
  CallbackType mCallbacks;
  
  void Foo(const string &amp;name, function&lt;float ()&gt; f)
  {
      mCallbacks[name] = make_pair(any(f), CLASS::e_float);
  }
  void Foo(const string &amp;name, function&lt;int ()&gt; f) { /* the same, but with e_int */ }
  void Foo(const string &amp;name, function&lt;double ()&gt; f) { /* the same, but with e_double */ }
  </code></pre>
  
  <p>Now I have in map boost function, packed into <strong>any</strong> with given type from enum, to recognize it in future. Now I have to call given functions. The casting from any won't work:</p>
  
  <pre><code>BOOST_FOREACH(CallbackType::value_type &amp;row, mCallbacks)
  {
      // pair&lt;any, TypeEnumerator&gt;
      switch (row.second.second) // Swith the TypeEnumerator
      {
          case 0: // int
              any_cast&lt; function&lt;int ()&gt; &gt;(row.first)();
          break;
          case 1: // float
              any_cast&lt; function&lt;float ()&gt; &gt;(row.first)();
          break;
          case 2: // double
              any_cast&lt; function&lt;double ()&gt; &gt;(row.first)();
          break;
      }
  }
  </code></pre>
  
  <p>This won't cast and during running I get the exception:</p>
  
  <pre><code>  what():  boost::bad_any_cast: failed conversion using boost::any_cast
  </code></pre>
  
  <p>Is it possible to convert back the <strong>boost::function</strong> object?</p>