Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erase old version abi before insert new version abi when set abi #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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