如何绑定变体apply_viewer

How to bind a variant apply_visitor?

本文关键字:apply viewer 何绑定 绑定      更新时间:2023-10-16

我有这个(C++03)代码,但不知怎么的,bind拒绝工作。有什么想法吗?

typedef boost::variant<int, string> Container;
std::vector<Container> v; 
...
class IsBad: public boost::static_visitor<>
{
public:
    typedef bool result_type;
    result_type operator()(int& t) const    { return  i % 2;     }
    result_type operator()(string& s) const { return s == "foo"; }
};
IsBad isBad;
std::vector<Container>::iterator it2 = 
         std::find_if(it, itEnd, bind(apply_visitor(isBad, _1)));
// bool is not a class, struct or union type

您不必使用bindapply_visitor(isBad)已经为您返回了一个函子。