があり、std::set
同様の隣接する要素を消去する必要があります:
DnaSet::const_iterator next = dna_list.begin();
DnaSet::const_iterator actual = next;
++next;
while(next != dna_list.end()) // cycle over pairs, dna_list is the set
{
if (similar(*actual, *next))
{
Dna dna_temp(*actual); // copy constructor
dna_list.erase(actual); // erase the old one
do
{
dna_temp.mutate(); // change dna_temp
} while(!dna_list.insert(dna_temp).second); // insert dna_temp
}
++actual;
++next;
}
プログラムがメインループから抜け出せないことがあります。の最後の要素を消去すると問題が発生すると思いますdna_list
。このタスクを実行する正しい方法は何ですか?