On the topic of generating unique index IDs for objects, I thought about using the numeric value of their pointers as ID. Since they are always guarenteed to be unique, it would save me the trouble of generating unique numbers without worrying about overlap.
Basically:
typedef uintptr_t T_Index;
T_Index getIndex()
{
return (T_Index)this;
}
My question is, would this be safe? Or could pointer addresses change in some way? Obviously move operations would invalidate the index, but if move construction and move assignment are disabled, would it be safe?
This question is similar: How bad is to use integer pointers as unique ids? C++11, but the scope of that question is quite vague. Most people there primarily seem concerned with performance and such, and the OP there stated his objects are never destroyed (which in my case is pretty much certain to happen). My question is not about performance, but about whether or not pointer-based unique indices would be safe to use on un-movable objects.
Minor side topic: Obviously pointers wouldn't work across multiple processes or multiple computers. Although I imagine one could still have a single process/computer dealing out indices (you probably should, anyway) and possibly append a process/computer/IP/port ID as needed.