unordered map - A non-loop efficient way to erase from unordered_map with predicate C++11? -


algorithms , member functions suggested on looping efficiency when working containers. however, associative containers (unordered_map) not work erase(remove_if) paradigm, appears common method fall on loop.

uom std::unordered_map

for(auto = uom.begin() ; it!=uom.end(); ){     if(it->second->toerase()) {         delete it->second; // omit delete if using std::unique_ptr         fpc.erase(it++);     }else{         ++it;     } } 

//as per scott meyers effective stl pg45

is efficient possible? seams there should better way using erase(remove_if) paradigm works unordered_map (i understand associative containers cannot "re-ordered" hence non-support of remove_if algorithm). best way erase entries unordered_map using predicate? suggestions?

thank in advance.

that efficient possible. if want more convenient, use boost's erase_if template - see here. unordered_map maintains linked list of nodes in each bucket, it's cheap erase them. there's no need of remove-if type "compaction", suits std::vector's use of contiguous memory.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -