Skip to content

Conversation

@gzliudan
Copy link

Because element keys in a map are unique, the insertion operation checks whether each inserted element has a key equivalent to the one of an element already in the container, and if so, the element is not inserted. So when we set a contract of new version, we must erase old version first. Otherwise the new contract is not inserted, and the old contract is still in context.

…t insert new element when there's same key already in it
context->contracts.insert({name{contract}, std::move(c)});
const name key {contract};
context->contracts.erase(key);
context->contracts.insert({key, std::move(c)});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to use: context->contracts.insert_or_assign(name{contract}, std::move(c));

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, insert_or_assign is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants