Boost logo

Boost Users :

Subject: [Boost-users] [proto-docs] Customing Expression Trees - why three args in operator()?
From: Markus Werle (numerical.simulation_at_[hidden])
Date: 2008-09-25 05:00:34


Hi!

[@Eric: The docs look much greater now. Thank you for the hard work.
As I can afford time I will go through the docs step by step,
give comments again and ask silly questions like before.
Is it OK for You that this happens on the public ML?
IMHO this may help others, too.
Some remarks are rather nitpicking stuff, but still considered to be helpful
for first time users of proto]

In this post I refer to
<http://boost-sandbox.sourceforge.net/libs/proto/doc/html/
boost_proto/users_guide/getting_started/hello_calculator.html>

Q1: Probably a typo: Is it "Customing" or "Customizing"?

Q2: It is not clear to me why operator() has 3 arguments:

double operator()(double a1 = 0, double a2 = 0, double a3 = 0) const
    {
        calculator_context ctx;
        ctx.args.push_back(a1);
        ctx.args.push_back(a2);
        ctx.args.push_back(a3);
        
        return proto::eval(*this, ctx);
    }

IMHO the whole thing should work even without the 3rd argument.
Can you explain?

R1: For didactic reasons I would add examples that do not rely on the
assumption that the user knows STL by heart, e.g. immediately before

<cite>
// Use std::transform() and a calculator expression
// to calculate percentages given two input sequences:
std::transform(a1, a1+4, a2, a3, (_2 - _1) / _2 * 100);
</cite>

please add the following code:

double const result = ((_2 - _1) / _2 * 100)(45.0, 50.0);
BOOST_ASSERT(result == (50.0 - 45.0) / 50.0 * 100)); // is this portable?

This proposal is in analogy to the code presented in the boost::bind docs
at http://www.boost.org/doc/libs/1_36_0/libs/bind/bind.html, which I
always found _very_ helpful, since they separate one thing from another.

R2: In "Controlling Operator Overloads" it would help a lot if the
difference between the previous approach and the new approach
was written in *bold*, in order to hinder a scroll

proto::domain< proto::generator<calculator>, <BOLD>calculator_grammar</BOLD> >

or like this:

struct calculator_domain
// OLD version had default grammar
//: proto::domain< proto::generator<calculator> >
  : proto::domain< proto::generator<calculator>, calculator_grammar >
{};

best regards,

Markus

 


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