I am trying to generalize the functions filterX()
and filterY()
in the following class Table
to function filter()
.
A member function requires a pointer to the object instance. That is, think of getX
as string Row::getX(const Table *this)
. You need to bind
the member function with an instance placeholder.
E.g. using tr1,
vector vx = t.filter("x1", std::bind(&Row::getX, std::placeholders::_1));
The binding creates a functor that takes in a Row
object, assuming that your filter function is correctly defined. You should show code for filter
. I presume it should be:
template
vector Table::filter(const string &s, function f)
{
vector result;
for (vector::const_iterator it = d_table.begin(), tEnd = d_table.end();
it != tEnd; ++it)
{
if (s == f(*it)) result.push_back(it->getVal());
}
return result;
}