I have a map container. I want to copy all its keys with user specified first letters to a vector. How to do that in an efficient way? Thank you!
std::map(std:string, size_t) myMap;
myMap.insert(std:make_pair("Ace", 11);
myMap.insert(std:make_pair("Ape", 12);
myMap.insert(std:make_pair("Age", 13);
myMap.insert(std:make_pair("Beat", 21);
myMap.insert(std:make_pair("Boat", 22);
myMap.insert(std:make_pair("Boss", 23);
myMap.insert(std:make_pair("Coat", 31);
myMap.insert(std:make_pair("Cost", 32);
myMap.insert(std:make_pair("Cast", 33);
For example, if I want to extract all the element(s) with their keys starting with “Bo” from myMap and populate the satisfled results to myVec, myVec will have the following elements:
Boat
Boss
Declarations left out for brevity:
You can implement the
first_does_not_begin_withfunctor class, right? It’s operator should have this signature: