我大致有以下代码.这可以更好或更有效吗?也许用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);
}
Run Code Online (Sandbox Code Playgroud) 我们将在我们的小团队中开始一个新项目:
不幸的是,我们的开发人员没有在Windows之外的任何其他平台上编写任何代码!因此,我必须给他们一个"像这样的代码"或"不像这样的代码"列表,所以代码将保持跨平台.
任何指导?