Improve Table copy assignment operator

This commit is contained in:
Raoul Wols 2021-07-01 12:06:35 +02:00
parent f52fdf6977
commit 0f17bd0687
No known key found for this signature in database
GPG Key ID: 9FFE06A0F6AAA2DF
1 changed files with 4 additions and 2 deletions

View File

@ -67,8 +67,10 @@ Table &Table::operator=(const Table &table)
// loop through the table records
for (auto iter = table._fields.begin(); iter != table._fields.end(); iter++)
{
// add the field
_fields[iter->first] = std::shared_ptr<Field>(iter->second->clone());
// since a map is always ordered, we know that each element will
// be inserted at the end of the new map, so we can simply use
// emplace_hint and hint at insertion at the end of the map
_fields.insert(_fields.end(), std::make_pair(iter->first, iter->second->clone()));
}
// done