#include #include #include template struct int_tuple {}; // make indexes impl is a helper for make indexes template struct make_indexes_impl; template struct make_indexes_impl, T, Types...> { typedef typename make_indexes_impl, Types...>::type type; }; template struct make_indexes_impl > { typedef int_tuple type; }; template struct make_indexes: make_indexes_impl<0, int_tuple<>, Types...> { }; template< class T, class... Args > struct cb_ { typedef void (T::*type)(Args...); }; template< class T, class... Args, int... Indexes > boost::function< void(Args...) > make_func_helper( typename cb_::type cb, T* that, int_tuple< Indexes... > ) { return boost::bind( cb, that, boost::arg()... ); } template< class T, class... Args > struct func { boost::function< void(Args...) > f; func( typename cb_::type cb, T* that) { f = make_func_helper( cb, that, typename make_indexes::type() ); } void call(Args...) { boost::function< void() > bound_fn = boost::bind(f, Args...); bound_fn(); // in effect the bound_fn will be stored in a queue for later envocation by a different thread } }; struct X { void f(int a, int b, double c) { std::cout << "a=" << a << " b=" << b << ", c=" << c << std::endl; } }; int main() { X x; func fn( &X::f, &x ); fn.f( 1, 2, 1.2 ); boost::function< void() > bound_fn = boost::bind(fn.f, 3, 4, 9.8); bound_fn(); fn.call(7, 3, 19.8); }