Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2005-10-23 20:13:37

On 10/23/2005 12:12 PM, Korcan Hussein wrote:
> I'll get back to you on that one, for the time being i have uploaded the
> example i have been writing about, it is in the vault here:
> In the example program you should see something similar, take note however

I ran it and tried to understand it. AFAICT, the key part of the code

template < typename Tp >
struct var {
        struct basic_eval : boost::static_visitor<float> {
                size_type curr_indx;

         basic_eval(size_type i = 0): curr_indx(i) {}

         float operator()(const Tp& val) const {
             return val[curr_indx];

         template < typename Expression >
         float operator()(const Expression& exp) const {
             using boost::apply_visitor;
             typedef typename Expression::operation_type Oper;

             float lhs_val=apply_visitor(*this, exp.get_lhs());
             float rhs_val=apply_visitor(*this, exp.get_rhs());
             float my_val=Oper::apply(lhs_val,rhs_val);
             return my_val;

I could see the Expression::operation_type is one of:


The apply_visitor is from:


and the body of this apply_visitor is:

   apply_visitor(const Visitor& visitor, Visitable& visitable)
     return visitable.apply_visitor(visitor);

Since there's no apply_visitor in the Expression<...> ,
I added a few variables (*_val) to store intermediate results to
enable using gdb to see what was going on.
After tracing several levels of calls in gdb in an effort to
find how:

   apply_visitor(*this, exp.get_lhs())

get's back to var<Tp>::basic_eval::operator(...), I finally just decided
it does, somehow, and since all variants of the var<Tp>::expr have
a corresponding exact match amoung the basic_eval::operator(...)'s,
not dynamic dispatching is done.

HTH any other reviewers of expr_test.cpp.

Boost list run by bdawes at, gregod at, cpdaniel at, john at