isNotZero<T>
is a member function, so it has an implicit first parameter for this
. You need a unary functor, so you will need to use std::bind
, to bind this
as the first parameter.
You also need to refer to the function as &Matrix::isNotZero<T>
. So,
using namespace std::placeholders;
auto f = std::function<bool(const T&)> f = std::bind(&Matrix::isNotZero<T>,
this, _1);
and use f
as the functor in count_if
.
Alternatively, use a lambda:
int count = count_if(m.begin(), m.end(),
[this](const T& val) { return this->isNotZero<T>(val);});