This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD status.

### 1296. `map` and `multimap value_compare` overspecified

Section: 24.4.4 [map] Status: NAD Submitter: Alisdair Meredith Opened: 2009-12-22 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [map].

View all issues with NAD status.

Discussion:

The container class templates `map` and `multimap` both contain a nested type called `value_compare`, that is used to compare the `value_type pair` elements, an adaptor of the user-supplied comparison function-like object.

I believe these types are over-specified, as we require a distinct type for each template, even though the allocator plays no part in the comparator, and `map` and `multimap value_compare` classes could easily be shared. The benefits are similar to the SCARY iterator proposal (although on a much smaller scale!) but unlike SCARY, this is not a QoI issue today but actively prohibited.

If the `value_compare` classes were marked 'exposition only', a vendor would be free to experiment with implementations that do not produce so many template instantiations with negligible impact on conforming programs. (There is a minor risk that programs could no longer portably overload functions taking `value_compare` types. This scenario is extremely unlikely outside conformance suites.)

(Note that there are no similar problems for unordered maps, nor any of the set variants)

[ 2010-01-31 Moved to Tentatively NAD after 5 positive votes on c++std-lib. Rationale added below. ]

Rationale:

The `value_compare` specification is an unfortunate bit from the past that we have to live with. Fortunately vendors can work around the problems mentioned in this issue.

Proposed resolution:

p2 24.4.4 [map]: Above the declaration of class `value_compare` in the map synopsis, add:

>     template <class Key, class T, class Compare = less<Key>,
>               class Allocator = allocator<pair<const Key, T> > >
>     class map {
>     public:
>       // types:
>       ...
>       // exposition only.
>       class value_compare
>         : public binary_function<value_type,value_type,bool> {
>         ...

p2 24.4.5 [multimap]: Above the declaration of class `value_compare` in the map synopsis, add:

>     template <class Key, class T, class Compare = less<Key>,
>               class Allocator = allocator<pair<const Key, T> > >
>     class multimap {
>     public:
>       // types:
>       ...
>       // exposition only.
>       class value_compare
>         : public binary_function<value_type,value_type,bool> {
>         ...