I am wondering if it is possible to create something like a predicate for a std::map for all of its values so I don’t have to edit the values before I insert them into the map.
What I would like is something like this:
mymap["username"] = " Marlon "; // notice the space on both sides of my name
assert(mymap["username"] == "Marlon"); // no more whitespace
The context is I am creating a std::map for a .ini file and I would like it to automatically remove leading/trailing whitespace from the values when I want to retrieve them. I’ve already created a predicate to ignore casing and whitespace from the key so I want to know if it is possible to do the same for the value.
You can have a wrapper class that wraps
std::stringandstd::stringstd::string.You can edit the value on the fly in either of these functions. You
std::mapcan hen have the wrapper as a key.With that said, it’s still better being a little more explicit, than clever, and have a separate INI class with its own get/set interface.