KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is it meant to be guaranteed that same std::type_info::hash_code() values imply same types? Cplusplus.com seems to claim so: This function returns the same value for any two type_info objects that compare equal, and different values for distinct types that do not. [Emphasis mine] Cppreference seems to claim otherwise: Returns an unspecified value, which is identical for objects, referring to the same type. No other guarantees are given , in particular, the value can change between invocations of the same program. [Emphasis mine] The relevant standards paragraphs are: ยง p18.7.1 p7-8 size_t hash_code() const noexcept; 7 Returns: An unspecified value, except that within a single execution of the program, it shall return the same value for any two type_info objects which compare equal. 8 Remark: an implementation should return different values for two type_info objects which do not compare equal. [Emphasis mine] What's the meaning of " should " supposed to be in the context above? If paragraph 8 is meant to be a requirement, then it seems impossible to fulfill unless the runtime does some kind of global uniquing over all symbol names in a program to ensure lack of hash collision, which seems to be a pretty big burden for the standard to foist upon implementations, especially for a function called hash_code() . (Itanium actually requires this, but it's explicitly an extra requirement above the standard.) If " should " is not meant to be binding, then the remark se
Tags (comma-separated)
Save Edits
Cancel