Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-05-28 04:04:39

----- 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.

> 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...

> Does anyone have a better way of doing this?

I don't think there is a better one within the current language rules.


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