0
Can I get event of modification into unordered_map or not
Refer code below: https://code.sololearn.com/c98nzq9fCQ9L I have an unordered_map of string and int. I am using [] operator each time as I need to modify value of existing element [as mentioned in function multiply]. What I need is to stop processing modification of existing value like umap["Eleven"] = -1; These type of statements are so many in code and can't check each and every such statements. This statement is just an example that I dont want few elements to be updated with certain values. Can I get some event which will be fired when umap["Eleven"] = -1; are called on unordered_map object? Feel free to ask for clarification in case of any query or confusion. Thanks in advance...!
3 odpowiedzi
+ 2
Then you could overload the [] function of the unordered map class. You can search up multiple tutorials on how to do this. Such as this https://stackoverflow.com/questions/21064979/c-specialization-of-operator-in-unordered-map
+ 1
You can use an if statement and the find method to check whether or not the value exist. Like this: if(map.find(“Eleven”) != map.end)
0
It won't work for me as code base is very large and can't do find and update for all entries simillar to below :
umap["Elevan"] = -1;