Boost logo

Boost Users :

From: Rainer Deyke (yg-boost-users_at_[hidden])
Date: 2003-05-11 15:31:27


Slava Akhmechet wrote:
> I was able to get boost::bind working to bind the semantic action to
> the member function of MyGrammar. This seems like a superior
> solution. In any case, I am not sure how to pass custom data to a
> functor. When specifing a semantic action I have to pass the type of
> the functor, which implies that spirit creates a temporary object. Am
> I missing something?

No, you pass an instance of the functor, which can be cosntructed with
arbitrary arguments.

struct functor {
  f(char const *s) : msg(s) {}
  template<class Iter> void operator(Iter, Iter)
  {
    std::cout << this->msg;
  }
  char const *msg;
};

parse(something, something_p[functor("something")]);

--
Rainer Deyke - rainerd_at_[hidden] - http://eldwood.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net