您如何检查是否find_if
找到匹配项?当我尝试下面的代码时:
SparseMatrix& SparseMatrix::operator+=(const SparseMatrix &other)
{
vector<Node>::iterator itThis;
for (vector<Node>::const_iterator itOther = other._matrix.begin(); itOther != other._matrix.end(); ++itOther)
{
itThis = find_if(_matrix.begin(), _matrix.end(), position_finder(*itOther));
if(*itThis)
{
itThis->value += itOther->value;
} else
{
_matrix.push_back(*itOther);
}
}
return *this;
}
我得到if(*itThis)
:
could not convert ‘itThis.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = Node*, _Container = std::vector<Node>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = Node&]()’ from ‘Node’ to ‘bool’
我知道这itThis
是一个常数,所以我不能改变它的值,但我想知道是否有匹配。