Boost logo

Boost Users :

Subject: [Boost-users] Boost.Proto embedding a function calls into expressions
From: Stefan Frehse (sfrehse_at_[hidden])
Date: 2010-03-25 11:00:11


Hello Boost.Proto,

firstly, thank you very much for your great work for providing such a
powerful framework.

My Setup: I defined a grammar, like grammar * grammar, a domain and so on.
Based on the domain two evaluator for different contexts are provided. For
standard operators that works great.
For expression evaluation I have a function defined as follow:

template<typename T, typename Expr, typename Arg0, typename Arg1, ... >
generate (T& t, Expr const& expr, Arg0 const& arg0, ... )
{
   call the first or the second evaluator switched by T and passes the value
arg0, ...
}
Therewith, I can write for example, generate (foo, _1 * _2, a, b);

Coming to my problem. I would like to write, generate (foo, _1 * func (_2,
_3), a ,b, c); Overall I would like to embedd function
calls into the expression and the pass them to the generate function.

I tried to implement a make_expr based on func, but that does not work for
me, i.e., compiler error for fmi::ite (_0, _1, _2) (a,b,c);

error: invalid use of incomplete type 'struct
fmi::ite_::result<fmi::ite_(boost::fusion::vector1<const fmi::bv&>,
boost::fusion::vector1<const fmi::bv&>,
boost::fusion::vector1<mpl_::void_&>)>'

error: declaration of 'struct
fmi::ite_::result<fmi::ite_(boost::fusion::vector1<const fmi::bv&>,
boost::fusion::vector1<const fmi::bv&>,
boost::fusion::vector1<mpl_::void_&>)>'
cpp:7:

Can you imaging what the problem is? Otherwise I will attach further cleaned
code.

struct ite_
  {
    template<typename Sig>
    struct result;

    template<typename This, typename If, typename Then, typename Else>
      struct result<This(If const&, Then const&, Else const&)>
      : fusion::result_of::make_vector<bv> {};

    template<typename If, typename Then, typename Else>
      fusion::result_of::make_vector<bv>::type operator() (If const& _if,
Then const& _then, Else const& _else) const
      {
        bv test;

/// some more code

        return fusion::make_vector (test);
      }

  };

 template<typename If, typename Then, typename Else>
 typename proto::result_of::make_expr<proto::tag::function
           , constraint_domain
           , ite_ const
           , If const&
           , Then const&
           , Else const&>::type
         ite (If const& _if, Then const& _then, Else const& _else)
         {
           return proto::make_expr<proto::tag::function, constraint_domain>(
                      ite_()
                    , boost::ref(_if)
                    , boost::ref(_then)
                    , boost::ref(_else));
           }

Examplarily, the placeholder definition:
  typedef constraint<proto::terminal<placeholder<mpl::int_<0> > >::type>
var0_type

Best wishes,
sfrehse



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