C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Introduction of value_equal to std::unordered_map / std::unordered_multimap

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Mon, 10 Apr 2023 13:54:34 -0400
On Mon, Apr 10, 2023 at 11:59 AM LoS via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Introduction of value_equal to
> std::unordered_map / std::unordered_multimap
>
> I. Motivation
> The std::map / std::multimap containers already provides a value_compare member class that
> allows to compare two value_type objects using the key_compare comparison object under
> the hood. This allows the user to directly call an instance of the value_compare comparison
> object and thus perform a compare operation between two value_type objects easily.
> However, it is not possible to do such a thing with the std::unordered_map /
> std::unordered_multimap containers, because they do not provide a member class that allows to
> compare two value_type objects in an equivalence relation using the key_equal object under
> the hood. Besides not being very consistent with the associative containers interface, this lack forces
> the user to always call an instance of key_equal and then pass the key part of the elements to the
> function object, or forces the user to implement his own lambda function or class funcrion that does
> the same thing under the hood.

But what is the reason to *want* to do that to begin with? What code
are you writing where this is useful or important?

That is, when does a user have two keys, a map object, and the desire
to compare them in the way that the map does? Can you give an example
of a circumstance where that need would arise?

Received on 2023-04-10 17:54:45