Rainer Deyke wrote:
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")]);
The preferred way is to keep the semantic functors as light as possible. As Rainer suggested, a pointer is ok. As for me, I prefer keeping a reference to some external data. Example: struct functor { f(T& data) : data(data) {} template<class Iter> void operator(Iter, Iter); T& data; }; BTW, I suggest continuing this thread here: Spirit-general mailing list Spirit-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/spirit-general -- Joel de Guzman joel at boost-consulting.com http://www.boost-consulting.com http://spirit.sf.net