|
Boost : |
From: joel de guzman (isis-tech_at_[hidden])
Date: 2001-05-28 03:17:38
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.
>>
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.
Does anyone have a better way of doing this?
Thanks,
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