I'm still working on a good solution to my One-Of-A-Type Container Problem -- and upon reflection I think it would be nice to be able to just use something like a std::map<std::type_info, boost::any>
. Unfortunately, std::type_info
does not define an operator<
, and I think it'd be unreasonable for it to define one.
However, it does seem reasonable to define a hash function for it, because you could simply use the singleton address of the std::type_info
object as a reasonable "hash". Therefore, you'd be able to put a std::type_info
into a std::unordered_map
as the key.
Does C++11 provide such a hash function? Would using the memory address of the std::type_info
singleton be a bad hash strategy?
You could also use type_index, it safely holds a pointer to a type_info, it's copyable, comparable and a hash function is provided for standard containers.
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