0

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
Niall
  • 30,036
  • 10
  • 99
  • 142
Sam
  • 19,708
  • 4
  • 59
  • 82
  • 1
    also, note that instead of nesting `typedef bool result_type;` you can put the return type in base class declaration, like `class IsBad : public boost::static_visitor` – Piotr Skotnicki Oct 09 '14 at 09:10

1 Answers1

3

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

Jamboree
  • 5,139
  • 2
  • 16
  • 36