Boost logo

Boost :

Subject: Re: [boost] [any] new version
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2011-08-31 23:26:04


On 09/01/2011 05:26 AM, Emil Dotchevski wrote:
> On Wed, Aug 31, 2011 at 5:55 PM, Ilya Bobir<ilya.bobir_at_[hidden]> wrote:
>> On Wed, Aug 31, 2011 at 5:16 PM, Martin Bidlingmaier
>> <Martin.Bidlingmaier_at_[hidden]> wrote:
>>> Hi,
>>>
>>> [...] It does not depend on rtti and uses a static integer value instead of std::type_info to store type information.
>>> [...]
>>
>> Quote from any.hpp:
>>
>> //use static class member to force initialization at program start
>> to make type_id thread safe (and more efficient)
>> template< class T>
>> class type_id
>> {
>> public:
>> static unsigned int value;
>> };
>> template< class T>
>> unsigned int type_id< T>::value = next_id();
>>
>> I do not think you can initialize a class static in a header. If you
>> include any.hpp in more than one cpp you will have the same static
>> been initialized more than once.
>> MS C++ linker complains. Though the standard requires no diagnostic.
>> See "9.4.2 Static data members" paragraph 5.
>
> In addition, in general, the initialization of statics and globals may
> be postponed until after main() is entered.

In addition, on most platforms there will be multiple instances of
type_id<T>::value for a single given T if the application uses
type_id<T> in multiple modules. These instances will be initialized
independently and most likely will have different ids. And since
next_id() is also module-private, inter-module passing of boost::any
becomes totally impossible.


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