
On 09/01/2011 08:16 AM, Ilya Bobir wrote:
On Wed, Aug 31, 2011 at 10:26 PM, Andrey Semashev <andrey.semashev@gmail.com> wrote:
[...]
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. [...]
Can you elaborate on this?
Are not you supposed to provide an explicit initialization for the type_id<T>::value for every T you are using and that would be the only instance?
I can not find anything in the standard that would contradict your statement, at the moment, except that if you treat a template instantiation as a class in this case you may say that 9.4.2 para. 5 applies to template instantiations and then there should be no more than once instance of a static member for a particular set of template arguments.
Yes, except that the Standard doesn't specify how that translates to a multi-module application (i.e. which consists of exe and dll/so/dylib). Because the Standard doesn't know of modules. Suppose you use boost::any with types int and string in your main executable and in one of the dlls linked in. Exe and dll will have separate instances of both type_id<int>::value and type_id<string>::value, each of them being initialized independently. What's worse, exe and dll will have separate next_id() functions with its local static counter. Depending on the circumstances, type_id<int>::value in exe may become initialized equal to type_id<string>::value in dll, for instance. Needless to say what will happen if you try to interoperate with boost::any's created in different modules. In practice, I'm aware of only one platform (Linux), which will by default attempt to maintain a single instance of these ids, but even there care must be taken.