2014-10-09 1 views
0

У меня есть этот код (C++ 03), но почему-то bind отказывается работать. Любые идеи почему?Как связать вариант apply_visitor?

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 
+1

также обратите внимание, что вместо вложения 'typedef bool result_type;' вы можете поместить возвращаемый тип в объявление базового класса, например 'class IsBad: public boost :: static_visitor ' –

ответ

3

Вы не должны использовать bind, apply_visitor(isBad) уже возвращает вам функтор.

Смежные вопросы