Is there a way for std::map to "edit" values like a predicate for the key?
Posted
by
Marlon
on Stack Overflow
See other posts from Stack Overflow
or by Marlon
Published on 2010-12-25T01:35:43Z
Indexed on
2010/12/25
1:54 UTC
Read the original article
Hit count: 534
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.
© Stack Overflow or respective owner