Boost logo

Boost :

From: Korcan Hussein (korcan_h_at_[hidden])
Date: 2005-10-22 15:04:38

"Larry Evans" <cppljevans_at_[hidden]> wrote in message
> On 10/21/2005 04:37 PM, Korcan Hussein wrote:
>> "Larry Evans" <cppljevans_at_[hidden]> wrote in message
> Please do. I'm guessing that the replica is encoded in the variant's
> which member function. IOW, just like the expression type in:
> encodes the type of expression as:
> variant.which() expression type
> ----------------------------------
> 1 int
> 2 binary_op<add>
> 3 binary_op<sub>
> your proposal would do the same for each possible value of expression
> type. IOW, instead of dynamic dispatching as done by type erasure,
> the dispatching would be done on variant.which()?

Something along the lines of that but not necessarily boost::variant::which,
use a static visitor (check boost::static_visitor) no dynamic dispatching
and no casting. Also you are not defining the structure of the tree since it
could come in any shape/form (which is the point of this), in certain
occasions only the types of leaf node operands are the most necessary info
to be given by a user just once the rest is automated.

Also (as I forget to mention earlier) boost::variant can not be used
directly on it's own since directly assigning/construction from a
compile-time expression tree will not work. You need to wrap it up, have a
template constructor that takes an expression tree and automates tree
construction, most of which is partially evaluated at compile-time, I have
code that does this already and is trivial. I also forgot to mention that
the most of the code used for the expression templates can be reused for

Another advantage of this over erasing type is that more nodes can easily be
added in other expressions, you could have a mix of compile-time & run-time
expression trees etc.

I did want to know if this has already been considered or already in use
before posting code but I think I'll go to tidy up what I have at the moment
to clarify things. Where should I post/put the example?

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