Wie filtere ich Elemente aus einer STD :: Karte? [Duplikat]C++

Programme in C++. Entwicklerforum
Anonymous
 Wie filtere ich Elemente aus einer STD :: Karte? [Duplikat]

Post by Anonymous »

Ich habe ungefähr den folgenden Code. Könnte dies schöner oder effizienter gemacht werden? Vielleicht mit STD :: REMED_IF ? Können Sie Elemente aus der Karte entfernen, während Sie sie durchqueren? Können wir vermeiden, die temporäre Karte zu verwenden? < /P>

Code: Select all

typedef std::map Actions;
static Actions _actions;

bool expired(const Actions::value_type &action)
{
return ;
}

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);
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post