Boost logo

Boost Users :

From: Mark Williams (mark.williams_at_[hidden])
Date: 2006-04-06 03:58:19


Having failed to find this elsewhere in boost, or in spirit, I rolled my
own - and it turned out to be a lot simpler than I expected:-

   struct assign_member_impl
   {
      template <typename Container, typename Member, typename Item>
      struct result
      {
         typedef void type;
      };
      template <typename Container, typename Member, typename Item>
      void operator()(Container& c, Member &m, Item const& item) const
      {
         c.*m = item;
      }
   };
   function<assign_member_impl> const assign_member_a =
assign_member_impl();

In a semantic action, we can then do something like this:-
  myrule = int_p[assign_member_a(myrule.m1, &foo::a, arg1)];

Mark

"Mark Williams" <mark.williams_at_[hidden]> wrote in message
news:e10t9b$86l$1_at_sea.gmane.org...
>
> Is there any standard way, in a semantic action, to assign individual
> elements of a struct that is set as a member of a closure? For example
> suppose I have:-
>
> struct foo {
> int a, b, c;
> std::string d;
> float e;
> };
>
> And I have this as member1 in my closure, which is then attached to a rule
> that parses each of those struct member elements seperately, is there then
> a standard way within the semantic actions in my rule to assign to foo.d,
> say, without modifying the other values? It seems that my only option is
> to either write my own functors to set each member seperately, or have the
> individual elements as seperate members of my closure.
>
> I kind of want to do something like this:
> myrule = int_p[assign_a(myrule.m1.a)] >> int_p[assign_a(myrule.m1.b)];
> But myrule.m1 is an actor, not an instance of foo.
>
> Is there a way to do this with boost::bind perhaps?
>
> I want to use closures since my rules need to be reentrant.
>
> Mark


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