You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
map::at() is implemented using at_impl, which itself is:
template <classThis, classKeyType>
staticinlineconstexprauto& at_impl(This&& self, KeyType const &key) {
auto where = self.lower_bound(key);
if (where != self.end())
return where->second;
elseFROZEN_THROW_OR_ABORT(std::out_of_range("unknown key"));
}
So whenever lower_bound succeeds, it returns the found value. But lower_bound returns whatever compares not less than - so a check is needed, that it is equal to? Possibly using find_impl.
The text was updated successfully, but these errors were encountered:
mikekaganski
changed the title
at() may return incorrect item
map::at() may return incorrect item
Jul 13, 2023
What code exactly are you looking at? Because this looks fine to me by doing almost exactly what you suggest (deferring to find, though not find_impl):
Uh oh!
There was an error while loading. Please reload this page.
map::at() is implemented using at_impl, which itself is:
So whenever
lower_bound
succeeds, it returns the found value. Butlower_bound
returns whatever compares not less than - so a check is needed, that it is equal to? Possibly usingfind_impl
.The text was updated successfully, but these errors were encountered: