ループ選択の条件に基づいています。if条件に基づいてforループを選択する
if(valid)
for (std::multimap<int,int>::reverse_iterator rit=id_count.rbegin(); mcount<10 && rit!=id_count.rend();++rit)
else
for (std::multimap<int,int>::iterator rit=id_match.begin(); mcount<10 && rit!=id_match.end();++rit)
{
//this is common for both for loop
}
これをC++でどのように実現するには?
ループ本体の中で共通の機能を使用しますか? – Lundin
C++ 14にアクセスできない場合は、 'std :: for_each'を使い、汎用ラムダを渡します。 – StoryTeller
@StoryTeller:追加の終了条件を持つ 'std :: for_each'?それはおそらくかなり醜い/非効率になるでしょう – MikeMB