Johnny2436
Utente Attivo
- Messaggi
- 322
- Reazioni
- 47
- Punteggio
- 45
Ragazzi mi potete aiutare? Ho visto questo codice in c++ in cui viene fatta tramite una funzione templetizzata, una operazione di merging tra due mappe, però non riesco a capire a cosa serva quel dest.insert(it1, *it2) all'interno del secondo if.
Codice:
template<class Map, class Merger>
void merge(Map& dest, const Map& source, Merger merger)
{
auto it1 = dest.begin();
auto it2 = source.begin();
auto&& comp = dest.value_comp();
for (; it1 != dest.end() && it2 != source.end(); ) {
if (comp(*it1, *it2)) {
++it1;
} else if (comp(*it2, *it1)) {
dest.insert(it1, *it2);
++it2;
} else { // equivalent
it1->second = merger(it1->second, it2->second);
++it1;
++it2;
}
}
dest.insert(it2, source.end());
}
Ultima modifica da un moderatore: