我正在尝试从list<boost::any> l中删除一个类对象
l.remove(class_type);我试着把类似这样的东西写成成员函数
bool operator == (const class_type &a) const //not sure about the arguments
{
//return bool value
}如何编写重载函数来从boost::any的std::列表中删除类的对象
发布于 2010-07-23 13:53:09
虽然您的operator==签名看起来很好,但为class_type重载它是不够的,因为boost::any并没有神奇地使用它。但是,对于删除元素,您可以将谓词传递给remove_if,例如:
template<class T>
bool test_any(const boost::any& a, const T& to_test) {
const T* t = boost::any_cast<T>(&a);
return t && (*t == to_test);
}
std::list<boost::any> l = ...;
class_type to_test = ...;
l.remove_if(boost::bind(&test_any<class_type>, _1, to_test));https://stackoverflow.com/questions/3315582
复制相似问题