I have several classes that act as a unique type identifier generator:
template<typename SK,typename T>
struct Component
{
static uint const index;
};
template<typename SK>
class ComponentCount
{
template<typename CSK,typename CT>
friend struct Component;
private:
template<typename T>
static uint next() {
return ComponentCount<SK>::get_counter();
}
static uint get_counter()
{
static uint counter = 0;
return counter++;
}
};
template<typename SK,typename T>
uint const Component<SK,T>::index(ComponentCount<SK>::template next<T>());
struct Key{};
Now say that I create the above class templates in different ways in several different libraries:
uint const x0 = Component<Key,int>::index;
uint const x1 = Component<Key,std::string>::index;
uint const x2 = Component<Key,double>::index;
uint const x0 = Component<Key,std::string>::index;
uint const x1 = Component<Key,double>::index;
uint const x2 = Component<Key,int>::index;
uint const x0 = Component<Key,int>::index;
uint const x1 = Component<Key,std::string>::index;
Is there any guarantee that a binary that references libsrc0, libsrc1 and libsrc2 will have a sequential definition of the Component :: index indices, with each index having a different value?
Component<Key,int>::index
Component<Key,std::string>::index
Component<Key,double>::index
source
share