I am creating a custom RTTI system for my event system. Below is the EventTypeInfo class. As you can see, it is noncopyable, just as std::type_info.
class EventTypeInfo
{
public:
EventTypeInfo(const EventTypeInfo&) = delete;
EventTypeInfo& operator=(const EventTypeInfo&) = delete;
inline bool operator==(const EventTypeInfo& other) const {
return this == &other;
}
};
The way I create these objects for every event class boils down to this:
template<class EventClass>
const EventTypeInfo& event::type::info()
{
static EventTypeInfo typeinfo;
return typeinfo;
}
Given that (1) these objects are created statically (which means they will last for the entire duration of the application), (2) they are noncopyable, and (3) there’s no way to modify an EventTypeInfo‘s fields without resorting to const_cast, is it enough for me to implement operator== is terms of this == &other, or did I miss something?
In case of a multi-modular application, I think each module might end up with its own copies of static type-info objects. Therefore just comparing an address might be not enough if your events can fly between modules.
As far as I know, RTTI system in GCC had this sort of problem in past, and it caused troubles. Eventually, GCC developers admitted it and fixed to use string comparison in GCC 4.5.
So I would suggest you to do pointer comparison first, and if it fails, then check with a more reliable mechanism.