I understand that std::multimap has the following hash table structure for the purpose of looking at it (it is listed...) (data structure is tree structure).
What should I do if I want to delete only DATA_A?
This is because it seems that only the key is used to delete elements that can be multi-imap, and the value cannot be deleted.
In the first place, is there a mechanism in multimap that removes values instead of keys and automatically packs empty parts?
Thank you for your cooperation.
Reference URL: http://vivi.dyndns.org/tech/cpp/multimap.html
c++
You can delete elements that you have already commented on in erase(iterator position)
.
// Version to be deleted by specifying a pair
template<class MultiMap>
voiderase(MultiMap&map, typenameMultiMap::value_type const&value){
map.erase(find(begin(map), end(map), value));
}
// Version to be deleted by specifying data
template<class MultiMap>
voiderase(MultiMap&map,typeNameMultiMap::mapped_type const&mapped){
map.erase(find_if(begin(map), end(map), & (auto const&value){
return std::get<1>(value) == mapped;
}));
}
int main() {
std::multimap<int,int>m {{0,0},{1,1}};
erase(m,{0,0});
erase(m,1);
}
For example, if you have a function like this, you can erase it, but if you can't find a pair or if you find more than one data, the design will change depending on the situation.
(That's why STL only provided basic functions such as deleting with iterator
).
683 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
545 PHP ssh2_scp_send fails to send files as intended
525 Uncaught (inpromise) Error on Electron: An object could not be cloned
545 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
546 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.