Title
Should the comparator of std::flat_map/std::flat_multimap be copied twice in some operations?
Status
new
Section
[flat.map][flat.multimap]
Submitter
Jiang An

Created on 2023-07-23.00:00:00 last changed 9 months ago

Messages

Date: 2023-07-23.00:00:00

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?

History
Date User Action Args
2023-07-23 00:00:00admincreate