frozen icon indicating copy to clipboard operation
frozen copied to clipboard

map::at() may return incorrect item

Open mikekaganski opened this issue 1 year ago • 1 comments

map::at() is implemented using at_impl, which itself is:

  template <class This, class KeyType>
  static inline constexpr auto& at_impl(This&& self, KeyType const &key) {
    auto where = self.lower_bound(key);
    if (where != self.end())
      return where->second;
    else
      FROZEN_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.

mikekaganski avatar Jul 13 '23 09:07 mikekaganski