
2013/5/11 Arthur Athrun <athrunarthur@gmail.com>:
Hi, everyone,
I'd like to propose a little modification of boost:: bind to expose more information in boost:: _bi:: bind_t. <...> With such modifications, we can access all binded arguments in the boost::_bi::bind_t. Here is a showcase.
template<class T, class VT>void Test(VT t, T * p = 0) { //This parameter is not binded, so ignore it! }template<class T, class VT>void Test(VT t, typename T::val_type * p = 0) { //T::val_type is the parameter's type, //and can use boost::is_same<T::val_type, ID_t>::value to check it! std::cout<<"great! we get a value here!"<<t.get()<<std::endl; }
template <class R, class F, class A1, class A2>void retrive_args(boost::_bi::bind_t<R, F, boost::_bi::list2<A1, A2> > & f) { Test<A1>(f.arguments()[_1]); Test<A2>(f.arguments()[_2]); }
int f(int a, double b) { std::cout<<a<<std::endl; return a; }
int main(int argc, char * argv[]) { double t = 1.0; retrive_args(boost::bind(f, _1, 0.2)); //Here will retrive the second parameters only. return 0; }
I don't know if I get the right way to implement it. Please let me know if you have another implementation. Any comments or ideas will be appreciated. Thanks.
Simpler solution would be to use boost::tuple or boost::fusion::vector to store and pass parameters separetly from function. Only after all the work with parameters done, call boost::bind and retrieve your functional object. -- Best regards, Antony Polukhin