मेरे पास लगभग निम्न कोड है। क्या यह अच्छा या अधिक कुशल बनाया जा सकता है? शायद std::remove_if
का उपयोग कर रहे हैं? क्या आप इसे ट्रैक करते समय मानचित्र से आइटम हटा सकते हैं? क्या हम अस्थायी मानचित्र का उपयोग करने से बच सकते हैं?std :: मानचित्र से आइटम कैसे फ़िल्टर करें?
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);
}
धन्यवाद, कि मोटे तौर पर क्या मैं भी –