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

3959. Should the comparator of std::flat_map/std::flat_multimap be copied twice in some operations?

Section: 23.6.8 [flat.map], 23.6.9 [flat.multimap] Status: New Submitter: Jiang An Opened: 2023-07-23 Last modified: 2023-07-23

Priority: Not Prioritized

View other active issues in [flat.map].

View all other issues in [flat.map].

View all issues with New status.

Discussion:

Currently, some operations of std::flat_map are specified to construct a key_equiv object for calling ranges::unique to remove duplicated elements. It seems that the comparator is required to be copied twice before calling ranges::unique.

If we make key_equiv to an aggregate class, then the comparator will be only copied once. Furtherly, if we use a std::reference_wrapper<const key_compare> as the member of key_equiv, then we will be able to avoid copying. Such differences seem to be observable.

Should we require to avoid copying, or explicitly say that implementations can either make copies or avoid copying?

Likewise, std::flat_map::value_comp and std::flat_multimap::value_comp seem to be required to copy the comparator twice due to the exposition-only constructor of value_compare.

Should we make the constructor take a const reference?

Proposed resolution: