I have a map<string, function> that maps command names to functions that need to be called on invocation of that function.
This has around 100 commands at present. The commands were inserted using make_pair() and when I print them out they are displayed in alphabetical order with the commands that have capitalised starting characters. E.g.
A
B
a
b
I was wondering if there is any simple way (during insert or displaying) that I can get these command names to be displayed with the capitalised starting characters ignored. E.g.
Candy wrote:use an std::string that makes character-insensitive compares (IE, with std::basic_string<char, my_char_traits<char> > ?)
Alternatively, supply a case-insensitive variant of std::less as the comparator function/functor (the third argument to std::map, defaults to std::less<KeyType>). That would allow "normal" strings to be used.
I was just wondering when the comparator function in map is called?
I think it should be only when we insert anything into the map? or are there any cases where this is called?
Neo wrote:I was just wondering when the comparator function in map is called?
I think it should be only when we insert anything into the map? or are there any cases where this is called?
The comparisone function would be called whenever you traverse the tree using a key. That would include insertions, removals, or finds.