If all your any
objects can be set at the same time, you can just hard-code the type for the function pointer then and there. Stuff it all into a seperate object and you're good to go. This is basically a double-take on type-erasure, and could also be implemented through virtual functions (like how boost::any
works internally), but I like this version more:
// note that this can easily be adapted to boost::tuple and variadic templates
struct any_container{
template<class T1, class T3, class T3>
any_container(T1 const& a1, T2 const& a2, T3 const& a3)
: _ichi(a1), _ni(a2), _san(a3), _somefunc(&somefunc<T1, T2, T3>) {}
void call(){ _somefunc(_ichi, _ni, _san); }
private:
boost::any _ichi, _ni, _san;
// adjust to your need
typedef void (*func_type)(boost::any&, boost::any&, boost::any&);
func_type _somefunc;
template<class T1, class T2, class T3>
void somefunc(boost::any& a1, boost::any& a2, boost::any& a3){
// access any objects with 'boost::any_cast<TN>(aN)'
}
};