Sam
Sam

Reputation: 20056

How to bind a variant apply_visitor?

I've got this (C++03) code, but somehow, bind refuses to work. Any ideas why?

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

Upvotes: 0

Views: 336

Answers (1)

Jamboree
Jamboree

Reputation: 5309

You don't have to use bind, apply_visitor(isBad) already returns you a functor.

Upvotes: 3

Related Questions