The question is in the comment section of the code block below.
Code:
#include <list>
#include <functional>
struct Foo
{
Foo():_bar(0){}
explicit Foo(const int bar):_bar(bar){}
int Bar() const {return _bar;}
bool less_equal(const int value) {return _bar <= value;}
private:
int _bar;
};
int main(int argc, char* argv[])
{
std::list<int> myInts;
std::list<Foo> myFoos;
for (int i=0; i<5; ++i)
{
myInts.push_back(i);
myFoos.push_back(Foo(i));
}
// Remove all values that are less than 4.
myInts.remove_if(std::bind2nd(std::less_equal<int>(),3));
myFoos.remove_if(std::bind2nd(std::mem_fun_ref(&Foo::less_equal),3));
// mInts = [1](4)
// myFoos = [1]({_bar=4})
// How do I do the same as the lines above using the Foo::Bar member
// function? The following obviously does not complete succesfully.
//myFoos.remove_if(std::bind2nd(std::bind2nd(std::less_equal<int>(),3)),
// std::mem_fun_ref(&Foo::Bar));
// In other words, I want to iterate through the list of Foo instances
// and call the Bar() member function and pass it to std::less_equal.
return 0;
}