
I need something similar to variant to optimize dynamic dispatches in my application much like what GIL uses. Unfortunately one of my target platforms does not support RTTI. How much does variant rely on the facilities of RTTI? Is it reasonable/possible to consider replacing RTTI to remove that dependency? I had to add a BOOST_NO_RTTI config macro locally several months ago in order to use lexical_cast. Perhaps RTTI could be used conditionally based on something similar. Thanks, Michael Marcin

Hello The variant library does not rely in any way on RTTI. That should solve your problem :-) Each variant instance stores an additional field describing the type of the contained object. Benoît Casoetto 2007/6/29, Michael Marcin <mmarcin@method-solutions.com>:
I need something similar to variant to optimize dynamic dispatches in my application much like what GIL uses. Unfortunately one of my target platforms does not support RTTI.
How much does variant rely on the facilities of RTTI?
Is it reasonable/possible to consider replacing RTTI to remove that dependency? I had to add a BOOST_NO_RTTI config macro locally several months ago in order to use lexical_cast. Perhaps RTTI could be used conditionally based on something similar.
Thanks,
Michael Marcin
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Benoît "When you have a hammer, everything else looks like a nail"

Benoit wrote:
Hello
The variant library does not rely in any way on RTTI. That should solve your problem :-) Each variant instance stores an additional field describing the type of the contained object.
Oh? Well if that's that case that is good news indeed however it is at least not entirely true. variant.hpp line 18 reads: #include <typeinfo> // for typeid, std::type_info And there appears to be a reflect class that uses typeid and std::type_info. The platform doesn't have these. Thanks, Michael Marcin

Michael, This is used by variant to support the variant::type method. Otherwise, as Benoit explained, it is not used. I know in the past there had been discussion about defining a BOOST_NO_RTTI macro, but I don't think this went anywhere...? If there were such a macro, the variant implementation could be changed to conditionally compile the variant::type method, etc. Eric On 6/29/07, Michael Marcin <mmarcin@method-solutions.com> wrote:
Benoit wrote:
Hello
The variant library does not rely in any way on RTTI. That should solve your problem :-) Each variant instance stores an additional field describing the type of the contained object.
Oh? Well if that's that case that is good news indeed however it is at least not entirely true.
variant.hpp line 18 reads:
#include <typeinfo> // for typeid, std::type_info
And there appears to be a reflect class that uses typeid and std::type_info.
The platform doesn't have these.
Thanks,
Michael Marcin
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Eric Friedman wrote:
This is used by variant to support the variant::type method. Otherwise, as Benoit explained, it is not used.
I know in the past there had been discussion about defining a BOOST_NO_RTTI macro, but I don't think this went anywhere...? If there were such a macro, the variant implementation could be changed to conditionally compile the variant::type method, etc.
Wouldn't it be cleaner to just deprecate that member function and reintroduce a freestanding version in a separate header (so the dependencies are as optional as the feature)? This takes some time, however, a fake 'typeinfo' header might serve as a short-term workaround to make code like variant compile as-is without RTTI: // unrefined and untested code for illustration only namespace std { struct RTTI_NOT_SUPPORTED; typedef RTTI_NOT_SUPPORTED type_info; } #define typeid *( ::std::type_info* )sizeof Regards, Tobias

Michael Marcin wrote:
I need something similar to variant to optimize dynamic dispatches in my application much like what GIL uses. Unfortunately one of my target platforms does not support RTTI.
variant doesn't really optimize dispatch. It probably does a binary search among the different possible types. Virtual functions are way more efficient.

The variant implementation (in GIL at least) performs a constant time dispatch. (Assuming the compiler reduces a switch statement of consecutive integers to constant time dispatch). Lubomir
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost- bounces@lists.boost.org] On Behalf Of Mathias Gaunard Sent: Friday, June 29, 2007 11:31 AM To: boost@lists.boost.org Subject: Re: [boost] [variant] RTTI
Michael Marcin wrote:
I need something similar to variant to optimize dynamic dispatches in my application much like what GIL uses. Unfortunately one of my target platforms does not support RTTI.
variant doesn't really optimize dispatch. It probably does a binary search among the different possible types. Virtual functions are way more efficient.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Mathias Gaunard wrote:
Lubomir Bourdev wrote:
(Assuming the compiler reduces a switch statement of consecutive integers to constant time dispatch).
That doesn't seem to be the case on the implementations I tried.
Try timing it. On modern CPUs, mispredicted branches affect the speed considerably. If indirect calls are never predicted, a jump table may turn out to be slower. What's even more interesting is that a plain linear search via if( x == 0 ) { ... } else if( x == 1 ) { ... } else if... may outperform a binary search because the branches predict better (there is a break-even N, of course, it's just higher than what we think).
participants (7)
-
Benoit
-
Eric Friedman
-
Lubomir Bourdev
-
Mathias Gaunard
-
Michael Marcin
-
Peter Dimov
-
Tobias Schwinger