I am wondering if hash_code()
of typeid is the same on different computers? For an example: if typeid(int).hash_code()
is it will be the same on another computer?
I am wondering if
hash_code()
of typeid is the same on different computers?
It may or may not be. From cppreference the behavior is:
Returns an unspecified value such that for all
type_info
objects referring to the same type, theirhash_code()
is the same.No other guarantees are given:
type_info
objects referring to different types may have the samehash_code
(although the standard recommends that implementations avoid this as much as possible), andhash_code
for the same type can change between invocations of the same program.
From cppreference :
hash_code for the same type can change between invocations of the same program
(cited from here).
So not only is it not guaranteed to be the same on different computers, it's not even guaranteed to be the same for the same program every time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With