我有
auto foo = [](FooPtr p) {return p->m_delete;};
std::deque<FooPtr> d = getD();
d.erase(std::remove(d.begin(), d.end(), foo), d.end());
我得到了大量的模板参数推断/替换失败的编译错误列表:
/opt/rh/devtoolset-3/root/usr/include/c++/4.9.2/bits/stl_deque.h:258:5: note: template argument deduction/substitution failed:
/opt/rh/devtoolset-3/root/usr/include/c++/4.9.2/bits/predefined_ops.h:191:17: note: 'std::shared_ptr<Foo>' is not derived from 'const std::deque<_Tp, _Alloc>'
{ return *__it == _M_value; }
/opt/rh/devtoolset-3/root/usr/include/c++/4.9.2/bits/predefined_ops.h:191:17: note: 'std::shared_ptr<Foo>' is not derived from 'const std::normal_distribution<_RealType>'
/opt/rh/devtoolset-3/root/usr/include/c++/4.9.2/bits/predefined_ops.h:191:17: note: 'std::shared_ptr<Foo>' is not derived from 'const std::list<_Tp, _Alloc>'
{ return *__it == _M_value; }
此列表会持续很长时间。知道我擦除删除的错误吗?
答案 0 :(得分:1)
您使用的是错误的算法。 std::remove()
期望一个值 - 一个FooPtr - 您应该使用std::remove_if()
来指定一个谓词。