2

Looking at cppreference, one can see that all std::map lookup functions (count, finds, contains, equal_range, lower_bound, upper_bound) have an overload taking a generic key argument (template< class K >) that is enabled if the comparator is transparent.

Why doesn't std::map::at offer the same overload taking a generic key type? It seems to me that std::map<std::string, T>::at would benefit from being able to take a std::string_view argument and not having to construct a temporary std::string key for the access.

I think it has something to do with strict weak ordering but I'm not sure.

Emile Cormier
  • 28,391
  • 15
  • 94
  • 122
  • Ah, sorry. I failed to find the duplicate question in my initial search. – Emile Cormier Feb 02 '23 at 19:49
  • 2
    I think I'll leave my question undeleted so that the duplicate Q&A can be found via the search terms I had used. – Emile Cormier Feb 02 '23 at 19:54
  • 5
    Leaving duplicates up as "signposts" this way is the recommended approach. They are part of a redirection feature of this site. See [Why are some questions marked as duplicate?](https://stackoverflow.com/help/duplicates) : *"If the question closed as a duplicate has no answers, then anonymous users will be automatically redirected to the question it is marked as a duplicate of. Some duplicate questions may eventually be deleted, but often they are left as a signpost pointing people towards the canonical answer to that question."* – François Andrieux Feb 02 '23 at 19:57
  • I did some sleuthing and ended up contributing an answer that attempts to resolve the question: https://stackoverflow.com/a/75329629/245265 – Emile Cormier Feb 02 '23 at 22:58

0 Answers0