おおよそ次のコードがあります。これをより良く、またはより効率的にすることはできますか? おそらく使用していstd::remove_if
ますか?移動中にマップからアイテムを削除できますか? 一時的な地図の使用を避けることはできますか?
typedef std::map<Action, What> Actions;
static Actions _actions;
bool expired(const Actions::value_type &action)
{
return <something>;
}
void bar(const Actions::value_type &action)
{
// do some stuff
}
void foo()
{
// loop the actions finding expired items
Actions actions;
BOOST_FOREACH(Actions::value_type &action, _actions)
{
if (expired(action))
bar(action);
else
actions[action.first]=action.second;
}
}
actions.swap(_actions);
}