Hi, everyone,
I'd like to propose a little modification of boost:: bind to expose more
information in boost:: _bi:: bind_t.
Here is my motivation problem. Suppose this is a function which takes boost:
:_bi::bind_t as a parameter. But at the same time, I'd like to enumerate
all binded parameters and do something for specific types, like the
following pseudo code shows.
template< class F>
void foo(F & f)
{
foreach(T& arg, f.arguments())
{
if(boost::is_same::value) //here ID_t is a user specific
type
//do something for arg.
}
}
I found that all binded arguments are stored in a listN object. But
unfortunately, the list object (L _l in boost::_bi::bind_t) is set to
private access and there is no method to boost::_bi::bind_t to access the
listN object and the type of listN.
I don't know why you developers didn't provide a method to access the
listN object.
But it seems reasonable to provide a public method in
, like this
typedef L argu_type;
const L & arguments() const {return l_;}
Also, the class "template<class T> class value" in
doesn't provide any access to T. It will be reasonable to add access
of type T, like this
public:
typedef T val_type;
With such modifications, we can access all binded arguments in the
boost::_bi::bind_t. Here is a showcase.
templatevoid Test(VT t, T * p = 0)
{
//This parameter is not binded, so ignore it!
}templatevoid Test(VT t, typename T::val_type * p = 0)
{
//T::val_type is the parameter's type,
//and can use boost::is_same::value to check it!
std::cout<<"great! we get a value here!"<void
retrive_args(boost::_bi::bind_t > &
f)
{
Test<A1>(f.arguments()[_1]);
Test<A2>(f.arguments()[_2]);
}
int f(int a, double b)
{
std::cout<