Skip to content

map::at() may return incorrect item #156

@mikekaganski

Description

@mikekaganski

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions