I’m using std::map to store to pointers to a class I use to wrap objects of different types. It’s being used to represent a table from the Lua scripting language, as well as other Lua types. While I was making my table wrapper I realized std::map would be using the default comparator when storing my pointers in the tree. At first this seemed like a problem to me, but then I thought about it some more and decided it wouldn’t be. Whatever the default comparison is, it shouldn’t really matter (I think).
So, what I’m asking is this. Is it true that it doesn’t really matter, and if so when would one want to use a custom comparator?
I think your question lacks a bit of clarity. Let’s assume you mean:
In that case, comparing the pointers by address is fine. However, for this use case, you might want to use an
unordered_map(aka hash table), officially available in C++11 but often available in c++ libraries even for C++03.