私はコールバック関数のセットを反復処理しています。関数は反復中に呼び出され、関数セットの実際のコンテナに大幅な変更をもたらす可能性があります。変更コンテナの反復
- が
- 反復コピー以上のオリジナルセットのコピーを作成しますが、すべての要素のために、それはまだ元のセット
チェックに存在するかどうかをチェックします。
私が今やっていることですすべての要素の存在が超ダイナミックですが、かなり遅いようです。
このケースに取り組む他の提案はありますか?
編集:
// => i = event id
template <class Param>
void dispatchEvent(int i, Param param) {
EventReceiverSet processingNow;
const EventReceiverSet& eventReceiverSet = eventReceiverSets[i];
std::copy(eventReceiverSet.begin(), eventReceiverSet.end(), std::inserter(processingNow, processingNow.begin()));
while (!processingNow.empty()) {
EventReceiverSet::iterator it = processingNow.begin();
IFunction<>* function = it->getIFunction(); /// get function before removing iterator
processingNow.erase(it);
// is EventReceiver still valid? (may have been removed from original set)
if (eventReceiverSet.find(ERWrapper(function)) == eventReceiverSet.end()) continue; // not found
function->call(param);
}
};
あなたはSTD :: <> ''設定意味ですか?そうでない場合は、実際のコンテナタイプは何ですか? – ildjarn
まあ、私はこの一般的なままにしたかったが、はい、それは標準です:: set –