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

map中的at #164

Open
Peas-Li opened this issue Oct 30, 2024 · 0 comments
Open

map中的at #164

Peas-Li opened this issue Oct 30, 2024 · 0 comments

Comments

@Peas-Li
Copy link

Peas-Li commented Oct 30, 2024

mapped_type& at(const key_type& key)
{
iterator it = lower_bound(key);
// it->first >= key
THROW_OUT_OF_RANGE_IF(it == end() || key_comp()(it->first, key),
"map<Key, T> no such element exists"); //lower_bound查找的是第一个不小于key的节点,这里应该判断的是key_comp()(key, it->first),如果为false说明key = if->first,那么就可以返回了
return it->second;
}

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

No branches or pull requests

1 participant