Boost logo

Boost :

Subject: Re: [boost] [any] new version
From: Roberto Hinz (robertohinz2_at_[hidden])
Date: 2011-09-03 01:11:25


Hi all,

I see another solution for the cross-dll problem, but it has two
disavantages:
1) it is not possible in a header-only library.
2) initialization type_id< T >::value is much slower. ( but any_cast() will
be as fast )

If this is unacceptable, then it doesn't worth to continue reading this.

Otherwise, the solution is to combine the numerical id approach ( to gain
performance in any_cast() ) with RTTI
Instead of using function next_id(), we do:

template< class T >
unsigned int type_id< T >::value = get_int_type_id<T>();

Function get_int_type_id<T> aways returns the same value for the same type T
regardless of the library it is called from. To achieve this, a std::map is
used ( although std::set maybe is more approprieate. I used std::map to make
the sample code simpler ). This map takes typeid(T).name() as the key, and
returns a unique integer value. This map would be instantiated in the
compiled library any.a ( or any.so or any.dll )

Regards,
Roberto Hinz




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk