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.
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: 2025-10-21
Priority: 3
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.
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?
[2025-10-21; Reflector poll.]
Set priority to 3 after reflector poll.
We should provide blanket wording to specify that comparators, hashers, allocators, etc. can be copied as often or as little as needed. Consider generalizing 3049(i).
Proposed resolution: