std::vector of std::function

隐身守侯 提交于 2019-12-01 20:48:21

You can store boost::function in the vector, provided you don't use std::find. Since you seem to need this, wrapping the function in its own class with equality would be probably the best.

class EventFun
{
  int id_;
  boost::function<...> f_;
public:
  ...
  bool operator==(const EventFun& o) const { return id_==o.id_; } // you get it...
};

Note that this requires you maintain the id_ in a sane way (eg. two different EventFuns will have different id_s, etc.).

Another possibility would be to store boost::functions with a tag the client would remember and use to identify the particular function on deleting it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!