Skip to content

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

Description

@Randalphwa

Migrated from the original repository
Original issue: serge-sans-paille/frozen#156
Originally reported by: @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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions