本文整理汇总了C++中map_t::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ map_t::erase方法的具体用法?C++ map_t::erase怎么用?C++ map_t::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map_t
的用法示例。
在下文中一共展示了map_t::erase方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: erase
// erase
size_t erase(const KEY_T& key) {
if (file_mode == READ_ONLY) {
throw std::runtime_error("Error: erase called in RO mode");
}
size_t num_erased = map->erase(key);
return num_erased;
}
示例2: prune
/** Prune the cache back to a given size.
* If the cache is larger than the maximum, the oldest entries
* will be deleted.
* @post size() <= max_size
* @param max_size The maximum cache size */
void prune (size_t max_size)
{
while (size_ > max_size)
{
map_.erase(list_.back().first);
list_.pop_back();
--size_;
}
}
示例3: remove
/** Remove an element from the cache. */
void remove (const key_type& k)
{
auto found (map_.find(k));
if (found == map_.end())
return;
list_.erase(found->second);
map_.erase(found);
--size_;
}
示例4: prune_if
void prune_if (size_t max_size, pred op)
{
if (list_.empty())
return;
auto i (std::prev(list_.end()));
while (size_ > max_size)
{
if (op(*i))
{
map_.erase(i->first);
i = list_.erase(i);
--size_;
}
if (i == list_.begin())
return;
--i;
}
}
示例5: set_fields_if_equals
bool set_fields_if_equals(doid_t do_id, const map_t &equals, map_t &values)
{
m_log->trace() << "Setting fields if equals on obj-" << do_id << endl;
YAML::Node document;
if(!load(do_id, document))
{
values.clear();
return false;
}
// Get current field values from the file
const Class* dcc = g_dcf->get_class_by_name(document["class"].as<string>());
ObjectData dbo(dcc->get_id());
YAML::Node existing = document["fields"];
for(auto it = existing.begin(); it != existing.end(); ++it)
{
const Field* field = dcc->get_field_by_name(it->first.as<string>());
if(!field)
{
m_log->warning() << "Field '" << it->first.as<string>()
<< "', loaded from '" << filename(do_id)
<< "', does not exist." << endl;
continue;
}
vector<uint8_t> value = read_yaml_field(field, it->second, do_id);
if(value.size() > 0)
{
dbo.fields[field] = value;
}
}
// Check if equals matches current values
bool fail = false;
for(auto it = equals.begin(); it != equals.end(); ++it)
{
auto found = dbo.fields.find(it->first);
if(found == dbo.fields.end())
{
values.erase(it->first);
fail = true;
}
else if(it->second != found->second)
{
values.erase(it->first);
fail = true;
}
}
// Return current values on failure
if(fail)
{
for(auto it = values.begin(); it != values.end(); ++it)
{
it->second = dbo.fields[it->first];
}
return false;
}
// Update existing values on success
for(auto it = values.begin(); it != values.end(); ++it)
{
dbo.fields[it->first] = it->second;
}
write_yaml_object(do_id, dcc, dbo);
return true;
}
示例6: Free
//Deletes the entry of a key in the resource map.
//This will call deleter_type to deallocate the resource from memory as well.
void Free(key_type const &key) noexcept
{
map_i i = m_map.find(key);
m_map.erase(i);
}