Boost logo

Proto :

Subject: Re: [proto] Visitor Design Pattern
From: Eric Niebler (eric_at_[hidden])
Date: 2010-10-22 17:36:15


On 10/22/2010 10:45 AM, Eric Niebler wrote:
> On 10/22/2010 10:01 AM, Thomas Heller wrote:
>> I think this is the simplification of client proto code we searched for. It
>> probably needs some minor polishment though.
> <snip>
>
> Hi Thomas, this looks promising. I'm digging into this now.

This is so wonderful, I can't /not/ put this in Proto. I just made a
small change to proto::matches to VASTLY simplify the implementation
(sync up). I also made a few changes:

- The action CRTP base is no more. You can't legally specialize a member
template in a derived class anyway.

- Proto::or_, proto::switch_ and proto::if_ are the only branching
grammar constructs and need special handling to find the sub-rule that
matched. All the nasty logic for that is now mixed in with the
implementation of proto::matches (where the information was already
available but not exposed).

- You have the option (but not the obligation) to select a rule's
default transform when defining the primary "when" template in your
actions class. (You can also defer to another action class's "when"
template for inheriting actions, but Thomas' code already had that
capability.)

- I changed the name from "_traverse" to "algorithm" to reflect its role
as a generic way to build algorithms by binding actions to control flow
as specified by grammar rules. I also want to avoid any possible future
conflict with Dan Marsden's Traverse library, which I hope to reuse in
Proto. That said ... the name "algorithm" sucks and I'd like to do
better. Naming is hard.

- The algorithm class is also a grammar (in addition to a transform)
that matches its Grammar template parameter. When you pass an expression
that does not match the grammar, it is now a precondition violation.
That is consistent with the rest of Proto.

That's it. It's simple, elegant, powerful, and orthogonal to and fits in
well with the rest of Proto. I think we have a winner. Good job!

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com



Proto list run by eric at boostpro.com