Boost logo

Boost :

From: joel de guzman (isis-tech_at_[hidden])
Date: 2001-06-07 02:24:12


----- Original Message -----
From: <jbandela_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, June 07, 2001 11:17 AM
Subject: [boost] Spirit and TYPEOF

> I have modified the Spirit example feat.cpp to use TYPEOF instead of
> Rule<>. All the code compiled and ran except for the last test. The
> last type generates more than 20 "entities/sizes" (see
> implementation, especially Sizes. Right now Typeof implementation
> supports only 20 (though that can be increased).
> Typeof.h comes from the TYPEOF directectory in boost files
> The following code compiles and runs under gcc 2.95.2
> Let me know what you think

Cool!

I just had a quick look at original post but hadn't yet got
deeper into it. Yes, I remember a spirit discussion regarding
the auto type declarator.

Just a few questions:

1. Is TYPEOF a macro?
2. How does it conform to GCC's and CodeWarrior's typeof
 and the typeof that is currently being proposed as a new C++ keyword?
3. How portable is it? Does it compile on different compilers/platforms?
4. How is it much better than other typeof implementations?
5. Where can I find your code?

Comments:

Spirit will really find such a facility useful. Before some sort of 'auto'
type declarator is accepted into C++, we could use the TYPEOF
engine to simulate the auto with another macro so instead of:

    TYPEOF(+digit >> '.' >> +digit) real = +digit >> '.' >> +digit;

We could easilly have:

    RULE(real, +digit >> '.' >> +digit);

Is there a better way, I don't know yet...

Tradeofs:

1. Macros
2. As Larry Evans noted, Rules are still necessary when forward declaring:

   A = 'a' >> A | 'b';

3. Clarity (readability). The original code without the typeofs is still
    much more readable, IMO.

That said, I think that it can be a nice addition (but not a requirement) to
Spirit for those who want to minimize the virtual function calls of
Rules<> if there are no recursive rule invocations involved. I think
such a facility should be a precursor to the proposed typeof operator
and should conform to it as closely as possible such that one could
just flick in an #ifdef switch with some compilers that already have it.

[snip]

Cheers,
Joel de Guzman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk