|
Boost : |
From: joel de guzman (isis-tech_at_[hidden])
Date: 2001-05-28 05:02:49
From: "David Abrahams" :
> ----- Original Message -----
> From: "joel de guzman" <isis-tech_at_[hidden]>
>
> > Hello,
> >
> > Here's a snip from spirit docs
> > <<
> > Rules straddle the border between static and dynamic C++.
> > In effect, a rule transforms compile-time polymorphism
> > (using templates) into run-time polymorphism (using virtual
> > functions). This is necessary due to C++'s inability to
> > automatically deduce the type of an arbitrarily complex type
> > in the right-hand side (rhs) and pass it on to the left-hand
> > side (lhs) of an assignment.
> > >>
>
> That's not really accurately phrased. C++ /can/ pass the type on to the
LHS
> of an assignment using a templated assignment operator. What it won't do
is
> let you declare a variable of deduced type.
Thanks for the correction. Yes in fact that's how the
Rule<> works.
>
> > I was trying to avoid virtual function at all costs. If only there
> > was a way in C++ to get the type of the rhs and pass it into
> > the lhs, I wouldn't have needed rules. In fact you can do away
> > with rules if you want to do more typing. Example:
> >
> > Alternative<ChLit<>, Sequence<ChLit<>, ChLit<> > > rule = a | b >> c;
> >
> > Assuming a, b and c are ChLits. It's the typing (pun intentional)
> > that necessitated Rules.
> >
> > There was a proposal in comp.std.c++ to reuse the auto
> > keyword to do this. With this extension, we could do:
> >
> > auto rule = a | b >> c;
> >
> > And Spririt will completely be static.
>
> That was my suggestion. Andy Koenig has an interesting idea which is even
> more flexible. Ask him about it sometime...
So that was you. OK. Nice idea. But don't keep me
in suspense. What's Andy Koenig cooking?
>
> > Does anyone have a better way of doing this?
>
> I don't think there is a better one within the current language rules.
>
> Sorry,
> Dave
I can wait.
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