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...!

13th Jul 2022, 12:10 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
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
16th Jul 2022, 3:48 PM
SimZooo
SimZooo - avatar
+ 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)
16th Jul 2022, 3:44 PM
SimZooo
SimZooo - avatar
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;
16th Jul 2022, 3:47 PM
Ketan Lalcheta
Ketan Lalcheta - avatar