|
Boost Users : |
From: Hubert Hoover (hugh_at_[hidden])
Date: 2007-01-04 14:08:23
For the record - I figured out my problem, which was a bit
of confusion about what was an actor and how to access closure members.
The "ref" passed in is a phoenix::actor, NOT the closure member itself,
so to access the closure member, the operator()() of the actor needs
to be invoked - substituting into the do_appender::act below:
String& value(ref());
value += val;
Of course, if act is called with something other than an actor, THIS
will
break, but I'm thinking it should ONLY be fed actors... And for my
purposes,
only an actor that returns a std::string&.
On Jan 2, 2007, at 17:09, Hugh Hoover wrote:
> I'm trying to build a parser that does a fairly simple
> transformation of an input string - kind of like an L-System.
> I can get rules to properly match the input string, but I'm having
> real trouble with DOING anything. For testing,
> I've created some simple actions and a grammar (and rules) with a
> closure. When I don't use the closure for
> "temporary" variables, I seem to be able to proceed, but when I do
> anything except assign a value to my closure
> result, I'm getting failures to compile. This is using gcc4.01 on
> MacOSX and spirit 1.8.3 (from boost 1.34).
>
> The specific compiler error is:
> ../../src/lsystem/catalog_lsystem.cpp: In member function 'void
> do_appender::act(T&, const IteratorT&, const IteratorT&) const
> [with T = phoenix::actor<phoenix::closure_member<0,
> phoenix::closure<String, size_t, String> > >, IteratorT =
> __gnu_cxx::__normal_iterator<char*, std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > >]':
> <snip>
> ../../src/lsystem/catalog_lsystem.cpp:211: error: no matching
> function for call to 'std::basic_string<char,
> std::char_traits<char>, std::allocator<char> >::basic_string
> (phoenix::actor<phoenix::closure_member<0, phoenix::closure<String,
> size_t, String> > >&)'
>
> From the error, it appears that I need some transformation from
> phoenix::actor
> back into my closure member, which is a String (typedef for
> std::basic_string<char>).
>
> Any suggestions?
>
> do_appender (a simple example actor) looks like:
>
> struct do_appender {
> template <typename T, typename ValueT>
> void act(T& ref, ValueT const &val) const
> {
> ref += val;
> }
>
> template <typename T, typename IteratorT>
> void act(T& ref, IteratorT const &first, IteratorT const &
> last) const
> {
> String s(first, last);
> ref += s;
> }
> };
>
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