Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-07-07 05:52:56

From: "Kevlin Henney" <kevlin_at_[hidden]>
> > From: "George A. Heintzelman" <georgeh_at_[hidden]>
> >I've been using the any.hpp currently out there quite successfully for
> >a little while. There are two main complaints that I have with the
> >current implementation. The first is easy to fix: for those situations
> >where you know for some reason what type is contained in the any, you
> >should be able to cast it without the overhead of checking the typeid,
> >which can (fer ex, in gcc) involve an expensive string comparison.
> Have you managed to demonstrate a significant overhead? I have not had
> the chance to perform significant performance checks, but across a
> couple of compilers I found a conversion to be between 50% and 200% more
> expensive than the equivalent unchecked versions. For the kind of type
> that boost::any is, and the places that it would be used, this does not
> strike me as a problem.

std::type_info::operator== can indeed be a bottleneck in some cases.
Implementations that make it work across application/DLL boundaries use a
string compare.


could be of some use to George. variant<T> uses a pointer compare to
determine the type (and as a result its to_ptr<> won't work correctly across
app/DLL boundaries, which is often not a problem in practice.)

I should point out, however, that variant<T> is twice as big as an 'any',
since it has different size/performance tradeoffs. (variant<void> is the
'any' equivalent.)

Peter Dimov
Multi Media Ltd.

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