Can I use boost :: bind () with mem_fun_ref ()?

My question is pretty simple: can I do something like this?

Say the class foo contains the following member function:

foo foo::DoSomething(input_type1 input1, input_type2 input2)
{
    ... // Adjust private datamembers
    return *this;
}

Using foo:

std::vector<foo> foovec;
input_type1 in1;
input_type2 in2;
...
std::transform(foovec.begin(), foovec.end(), foovec.begin(), std::mem_fun_ref(boost::bind(&foo::DoSomething, in1, in2)));

So is this possible? The problem is largely related to whether boost::bind()the membership / non-character nature of the function that it works on affects . I believe that I can not get around this:

std::transform(foovec.begin(), foovec.end(), foovec.begin(), boost::bind(std::mem_fun_ref(&foo::DoSomething), _1, in1, in2)));

because it std::mem_fun_ref()takes a unary or null function, and DoSomething()a binary one.

+3
source share
1 answer

You do not need std::mem_fun_ref, just use:

std::transform(foovec.begin(),
               foovec.end(),
               foovec.begin(),
               boost::bind(&foo::DoSomething, _1, in1, in2));

or you can replace boost::bindwith

std::bind(&foo::DoSomething, std::placeholders::_1, in1, in2)
+3
source

All Articles